我正在尝试运行以下命令以删除 e 代表发送权限,但我遇到了一个异常,它删除了所有有权访问的用户,而不是我在脚本中指定的用户
$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