2015-04-02 49 views
0

我想通過描述中存在的特定單詞在AD中找到計算機的描述。無法通過計算機掩碼在AD中進行搜索

$username = "test111" 
Get-ADComputer -filter {Description -Like 'test111*'} -Properties Description | select Description # this works ok 
Get-ADComputer -filter {Description -Like "$username*"} -Properties Description | select Description # shows nothing, no error 

如何使用變量進行搜索?

回答

1

你可以只是做一個查詢這樣的:

$username = "test111" 
Get-ADComputer -Filter "Description -Like '$username*'" -Properties Description | Select -Expand Description 

我認爲正在發生的事情是,$username大概$null,因爲它並沒有傳遞到腳本塊。將-Filter更改爲使用引號可使變量正確展開。在那裏扔了-Expand,所以你只需要返回一個字符串數組而不是Object數組。

相關問題