Hi All !
I've been using a function to acquire the property of an AD attribute:
function lookupUPN{ try{ $objDomain = New-Object System.DirectoryServices.DirectoryEntry $objSearcher = New-Object System.DirectoryServices.DirectorySearcher $objSearcher.SearchRoot = $objDomain $objSearcher.Filter = (&(objectCategory=User)(SAMAccountName=$Env:USERNAME)) $objSearcher.SearchScope = Subtree $objSearcher.PropertiesToLoad.Add(userprincipalname) | Out-Null $resultsUPN = $objSearcher.FindAll() ac $logfile "UPN search completed: $($resultsUPN[0].Properties.userprincipalname)" return $resultsUPN[0].Properties.userprincipalname }catch{ ac $logfile "Failed" } }
this works like a charm and gives me the users' UPN.
Now I would like to acquire the property of the attribute postalCode with this script:
function lookupLocation{ try{ $objDomain = New-Object System.DirectoryServices.DirectoryEntry $objSearcher = New-Object System.DirectoryServices.DirectorySearcher $objSearcher.SearchRoot = $objDomain $objSearcher.Filter = (&(objectCategory=Organization)(SAMAccountName=$Env:USERNAME)) $objSearcher.SearchScope = Subtree $objSearcher.PropertiesToLoad.Add(postalcode) | Out-Null $resultsLocation = $objSearcher.FindAll() ac $logfile "Location search completed: $($resultsLocation[0].Properties.postalcode)" return $resultsLocation[0].Properties.postalcode }catch{ ac $logfile "Failed" } }
Unfortunately, this code wont get me the data..
I keep getting 'Location search completed: ' with no location in it, while it is OK in AD..
I cant really figure out what i'm doing wrong here, i looked at the class in the AD schema..
Can someone see what the problem is ? :)
many thanks !
kind regards,
Thomas