
當我執行 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
答案1
是否可以取得檔案(txt 或 csv)中電腦物件清單的所有屬性,然後過濾所需的屬性?
是的。假設該檔案computers.txt
每行僅包含一個電腦名稱。
Get-Content computers.txt |
Get-ADComputer -Properties * |
Select-Object CanonicalName, CN, DistinguishedName
此外,您可以跳過-Properties *
(如果處理許多計算機,速度可能會很慢),只選擇除了預設屬性之外還要檢索哪些屬性。它DistinguishedName
包含在預設集中。
Get-ADComputer -Properties CanonicalName, CN
如果您有 CSV,則需要確定哪個列或標題名稱包含電腦名稱。如果您提供 CSV 格式的範例,我將更新我的答案。