powershell - Exchange 2010 PowerShell : Cannot bind argument

标签 powershell exchange-server-2010

我正在尝试从我们的 Exchange 服务器中的所有邮箱中删除孤立的用户对象。

当我执行这个命令时:

get-mailboxpermission * | where {$_.User -like "S-1-5-21*"} | foreach {$_.Identity.Name}

它正确地返回一个列表,其中包含仍然设置了孤立用户帐户权限的所有邮箱。

但是,当我尝试通过这样做删除它们时:
get-mailboxpermission * | where {$_.User -like "S-1-5-21*"} | remove-mailboxpermission -identity $_.Identity.Name -user $_.User -accessrights $_.AccessRights -deny:$_.Deny

它返回此错误:
Cannot bind argument to parameter 'Identity' because it is null.
+ CategoryInfo          : InvalidData: (:) [Remove-MailboxPermission], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Remove-MailboxPermission

我究竟做错了什么?

谢谢你的帮助。

最佳答案

$_那样不行,你需要包装Remove-MailboxPermission ForEach-Object {} 中的声明:

Get-MailboxPermission * | Where-Object {$_.User -like "S-1-5-21*"} | ForEach-Object {
  Remove-MailboxPermission -Identity $_.Identity.Name -User $_.User -AccessRights $_.AccessRights -Deny:$_.Deny
}

由于 Exchange 似乎不太喜欢嵌套管道,您可以简单地完全放弃参数参数(Remove-MailboxPermission 将自动绑定(bind)来自管道的权限):
Get-MailboxPermission * | Where-Object {$_.User -like "S-1-5-21*"} | Remove-MailboxPermission

关于powershell - Exchange 2010 PowerShell : Cannot bind argument,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33758267/

相关文章:

c# - 我的流媒体订阅去哪儿了?

c# - 在 Powershell 中使用名称参数构造函数创建对象

Powershell 忽略错误

powershell - powershell 脚本格式表输出中的颜色词

Powershell - 错误处理(如果已调用 Catch block ,则不要调用 finally block )

powershell - 导入 PSSession 在脚本中失败,在 shell 中工作

powershell 中的 html 对象错误

c# - 使用 Exchange Web Service 2010 查找所有未读电子邮件然后标记为已读?

php - 通过 PHP IMAP 连接到 Exchange 服务器,Exchange 服务器对 UNSEEN 电子邮件使用什么标志?

java - 如何使用 Microsoft Exchange 发送电子邮件附件?