【发布时间】:2018-10-07 16:52:48
【问题描述】:
我正在尝试在与添加到 $servers 数组的过滤器匹配的所有计算机上设置 ADComputer。但它不起作用。我想这与将对象传递给字符串有关,但我无法理解它。有人有黄金提示吗?
#Get gateway
$gateway = "MGMT01"
$gatewayObject = Get-ADComputer -Identity $gateway
#Get servers
$servers=@(Get-ADComputer -Filter {OperatingSystem -like "Windows Server*"} -Properties Name | select name | ft -HideTableHeaders)
#Create list of servers
Out-File -FilePath c:\adcomputers.txt -InputObject $servers
#Set WAC delegation
ForEach ($server in $servers)
{
$nodeObject = Get-ADComputer -Identity $server
Set-ADComputer -Identity $nodeObject -PrincipalsAllowedToDelegateToAccount $gatewayObject
}
错误:
Get-ADComputer:无法绑定参数“身份”。无法转换类型为“Microsoft.PowerShell.C”的“Microsoft.PowerShell.Commands.Internal.Format.FormatEndData”值 ommands.Internal.Format.FormatEndData”键入“Microsoft.ActiveDirectory.Management.ADComputer”。
在 C:\Users\SA.****\Desktop\inventorize-honolulu-incl-sso.ps1:7 char:40 + $nodeObject = 获取 ADComputer -Identity $server + ~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-ADComputer], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Management.Commands.GetADComputer
Set-ADComputer:无法验证参数“身份”上的参数。参数为空。为参数提供一个有效值,然后再次尝试运行该命令。
在 C:\Users\SA.****\Desktop\inventorize-honolulu-incl-sso.ps1:8 char:26 + 设置 ADComputer -Identity $nodeObject -PrincipalsAllowedToDelegateToAc ... + ~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Set-ADComputer], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.SetADComputer
【问题讨论】:
标签: arrays powershell object foreach active-directory