arrays - 如何将 AD 计算机名称传递给数组?
问题描述
我正在尝试在与添加到 $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 ommands.Internal.Format.FormatEndData”的“Microsoft.PowerShell.Commands.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:无法验证参数“身份”上的参数。参数为空。为参数提供一个有效值,然后再次尝试运行该命令。
在 C:\Users\SA.****\Desktop\inventorize-honolulu-incl-sso.ps1:8 char:26 + Set-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"
推荐阅读
- java - OneDrive 下载会话最长时间
- python - 使用 gridsampler 进行 PyTorch 图像转换,优化网格时的奇怪行为
- ruby-on-rails - 这个 ruby(rails) 代码是否易于阅读?
- javascript - 如何保持整个链接
- mysql - GitLab 工作停滞不前
- c# - 如何在浏览器中删除“localhost”之后的文本?
- python - 从 csv 文件中查找多列的中位数
- java - 最小/最大组合框动态功能
- sql - 在 Postgres 中返回 SETOF 表的函数
- java - 从另一个类控制器 Java (JavaFX) 到达选项卡 (TabPane)