0

我正在尝试运行以下命令以删除 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
4

1 回答 1

1

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

将最后一条语句更改为:

$grantlist | %{
    Set-Mailbox $owner -GrantSendOnBehalfTo @{Add=$_.Name} -Confirm:$true -DomainController tordc01
}
于 2015-03-10T15:31:51.967 回答