Exchange 2010 - Powershell 删除代表发送权限

Exchange 2010 - Powershell to remove Send On Behalf permission

我正在尝试 运行 下面的命令来删除 e Send On Behalf 权限,但我遇到了一个异常,它删除了所有具有访问权限的用户,而不是我在我的脚本

$owner = "lpeter" 
$remove = "jdoe"

$grantlist = Get-Mailbox $owner -DomainController tordc01 | select -ExpandProperty GrantSendOnB

$grantlist = $grantlist |?{$_.Name -ne $remove} 
Set-Mailbox $owner -GrantSendOnBehalfTo $null -DomainController tordc01
$grantlist | %{
    Set-Mailbox $owner -GrantSendOnBehalfTo @{Add=$_.Name} -Confirm $true
} -DomainController tordc01

这里是个例外:

ForEach-Object : Cannot bind parameter 'Process'. Cannot convert the
"-DomainController" value of type "System.String" to type
"System.Management.Automation.ScriptBlock". At line:1 char:15
+ $grantlist | % <<<< {Set-Mailbox $owner -GrantSendOnBehalfTo @{Add=$_.Name} -Confirm $true} -DomainController tordc01

     + CategoryInfo          : InvalidArgument: (:) [ForEach-Object], ParameterBindingException
     + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ForEachObjectCommand

异常是不言自明的,您试图将 -DomainController 参数提供给 ForEach-Object,而不是 Set-Mailbox

将最后一条语句更改为:

$grantlist | %{
    Set-Mailbox $owner -GrantSendOnBehalfTo @{Add=$_.Name} -Confirm:$true -DomainController tordc01
}