我正在尝试运行下面的命令来删除e Send代表权限,但是我得到了一个异常,它删除了所有有访问权限的用户,而不是我在脚本中指定的用户。
$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发布于 2015-03-10 15:31:51
异常非常不言自明,您正在尝试将-DomainController参数提供给ForEach-Object,而不是Set-Mailbox
将最后一条语句更改为:
$grantlist | %{
Set-Mailbox $owner -GrantSendOnBehalfTo @{Add=$_.Name} -Confirm:$true -DomainController tordc01
}https://stackoverflow.com/questions/28967201
复制相似问题