获取计算机对象属性以获取文件中服务器的列表

当我运行Get-ADComputer cmdlet时,可以查看所有单个对象的属性,如下所示。

C:\PS>Get-ADComputer "Fabrikam-SRV1" -Properties * AccountExpirationDate : accountExpires : 9223372036854775807 AccountLockoutTime : AccountNotDelegated : False AllowReversiblePasswordEncryption : False BadLogonCount : CannotChangePassword : False CanonicalName : Fabrikam.com/Computers/fabrikam-srv1 

然后,我可以过滤哪些属性显示在输出中。 这是可能得到一个文件中的计算机对象列表(txt或csv)的所有属性,然后过滤所需的一个?

像这样Get-ADComputer -Computer (Get-Content -Path .\computers.txt) | Select CanonicalName,CN,DistinguishedName Get-ADComputer -Computer (Get-Content -Path .\computers.txt) | Select CanonicalName,CN,DistinguishedName

这是可能得到一个文件中的计算机对象列表(txt或csv)的所有属性,然后过滤所需的一个?

是。 假设文件computers.txt包含一个单一的计算机名称每行。

 Get-Content computers.txt | Get-ADComputer -Properties * | Select-Object CanonicalName, CN, DistinguishedName 

而且,你可以跳过-Properties * (如果处理很多计算机的话可能会很慢),并且只select除了缺省值之外还要检索哪些属性。 DistinguishedName包含在默认集合中。

 Get-ADComputer -Properties CanonicalName, CN 

如果您有CSV,则需要确定哪个列或标题名称包含计算机名称。 如果您提供格式为CSV的示例,我会更新我的答案。