我尝试运行以下命令删除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
答案 0 :(得分:1)
异常非常明显,您尝试将-DomainController
参数提供给ForEach-Object
,而不是Set-Mailbox
将最后一个语句更改为:
$grantlist | %{
Set-Mailbox $owner -GrantSendOnBehalfTo @{Add=$_.Name} -Confirm:$true -DomainController tordc01
}