How to access displayName property value in object returned by DirectorySearcher? (newbie question)
hi all
i use following snippet loop thru ad , collect information users.
$adsearch = new-object system.directoryservices.directorysearcher
$adsearch.searchroot = $ad
$adsearch.filter = "(&(objectcategory=person)(objectclass=user)(!useraccountcontrol:1.2.840.113556.1.4.803:=2)(mail=*))"
$adsearch.searchscope = "subtree"
# fields should retrieved
foreach ($adprop in "cn","samaccountname","displayname","mail") {
$adsearch.propertiestoload.add($adprop) > $null
}
$adresult = $adsearch.findall()
foreach ($i in $adresult) {
$aduser = $i.properties
$user_list += $aduser.displayname + " (" + $aduser.mail + ") - " + $aduser.adspath + "`n"
}
unfortunately "displayname" property empty in result list. when using $aduser | fl while debugging can see it's there, can't figure out how it.
i assume newbie-question...help appreciated.
regards
/maurice
or try via item method:
$adresult[0].properties.item('displayname')
in case get:
ps c:\> $adresult[0].properties.item('displayname')
administrator
ps c:\> $adresult[0].properties.displayname
ps c:\>
Windows Server > Windows PowerShell
Comments
Post a Comment