gpt4 book ai didi

arrays - 如何将 AD 计算机名称传递给数组?

转载 作者:行者123 更新时间:2023-12-02 23:54:08 25 4
gpt4 key购买 nike

我正在尝试在所有匹配添加到 $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:无法绑定(bind)参数“Identity”。无法转换“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 = Get-ADComputer -Identity $server+ ~~~~~~~+ CategoryInfo : InvalidArgument: (:) [Get-ADComputer], ParameterBindingException+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Management.Commands.GetADComputer

Set-ADComputer:无法验证参数“Identity”的参数。参数为空。为参数提供有效值,然后再次尝试运行该命令。

在 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

最佳答案

要将服务器列表输出到文本文件,您只需要:

Get-ADComputer -Filter {OperatingSystem -like "Windows Server*"} |
Select-Object -ExpandProperty Name |
Out-File "c:\adcomputers.txt"

关于arrays - 如何将 AD 计算机名称传递给数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50052306/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com