2016-08-22 14 views
0

我想要使用PowerShell在AD用戶描述字段中獲得以特定關鍵字開頭的所有用戶。 關鍵字:無法執行的PowerShell在AD的描述字段中獲取具有特定關鍵字的AD用戶

Import-Module ActiveDirectory 

Get-ADUser -Filter * -SearchBase 'OU=contoso, DC=contoso, DC=local' - Properties Description | select -expand name,distinguishedname,description | Export-Csv -path C:\description.csv -NoTypeInformation 

最後更新:

Get-ADUser -Properties Description -Filter 'Description -like "*Could not execute powershell*"' -SearchBase 'OU=contoso, DC=contoso, DC=local' | 
select name,distinguishedname,description | 
Export-Csv -path C:\description2.csv -NoTypeInformation 

回答

2

這是使用-filter選項一件容易的事,你可以與get-aduser一起使用。

欲瞭解更多信息如何篩選:https://technet.microsoft.com/en-us/library/ee617241.aspx?f=255&MSPPError=-2147217396

下過濾位

Get-ADUser -Properties Description -Filter {Description -like $Description} -SearchBase 'OU=contoso, DC=contoso, DC=local' | select Name, DistinguishedName, Description | Export-Csv -path C:\description2.csv -NoTypeInformation 
+0

我得到了像Get-ADUser這樣的錯誤:無法綁定參數,因爲參數'Filter'被多次指定。要爲可以接受多個值的參數提供多個值,請使用數組syn syn tax。例如,「參數value1,value2,value3」。 – Arbelac

+0

@Arbelac看到我的更新,如果需要添加您的搜索庫。 – Jakodns

+0

像你說的那樣很好 – Arbelac

0

你可以簡單地篩選說明:

Get-ADUser -Properties Description -Filter 'Description -like "*Could not execute powershell*"' -SearchBase 'OU=contoso, DC=contoso, DC=local' 
+0

這將無法運行,你需要刪除-expand部分。 – Jakodns

相關問題