2
我有一個PowerShell腳本搜索活動目錄對於給定的用戶名和返回有關用戶屬性,這裏是腳本:PHP | PowerShell腳本輸出數據
Param([string]$username)
Import-Module ActiveDirectory
Get-ADUser $username -Properties GivenName, Surname, DisplayName, Enabled, PasswordExpired, Created, LastLogonDate
正如你所看到的,我已經給它我想要返回的屬性列表,併成功返回它。問題是,它還返回其他的東西,我不想要的,如「DistinguishedName」。在我所用回看下面:
Created : 30/07/2014 11:55:39
DisplayName : Testing Acount
DistinguishedName : CN=Testing Acount,OU=Disscuss,OU=Users,OU=Company,DC=Company,DC=local
Enabled : True
GivenName : Testing
LastLogonDate : 18/08/2014 12:27:40
Name : Testing Acount
ObjectClass : user
ObjectGUID : d135516b-4c10-41f1-9fa5-4f48bcacc891
PasswordExpired : False
SamAccountName : testingacount
SID : S-1-5-21-1161181520-173477490-3285844792-2188
Surname : Acount
UserPrincipalName : [email protected]
如何解決這樣的問題,使其只返回我所說的,甚至可能是通過它過濾後並去除不需要的位屬性。
這不是爲我工作得非常好。這就是我回來的:http://puu.sh/bctE1/aa8b609245.png,你可以看到,有些是空的,沒有結果。我將它改回舊的,所有的屬性都有值。 – Eclipse 2014-08-29 08:12:21
似乎從'Get-ADUser'函數返回的默認集合不會返回所有您想要的屬性,因此您必須使用-Properties參數,然後將其傳遞給Select-Object。 – 2014-08-29 14:45:00
完美,工作正常。謝謝 – Eclipse 2014-09-01 10:24:44