Here's my code:
write-host "username!name!objectguid!manager"
$Domain = 'LDAP://OU=Vancouver,DC=mycompany,dc=loc'
$Root = New-Object DirectoryServices.DirectoryEntry $Domain
Write-host "domain: $Domain"
$selector = New-Object DirectoryServices.DirectorySearcher([ADSI]"")
$selector.SearchRoot = $Root
$adobj= $selector.findall() |where {$_.properties.objectcategory -match "CN=Person"}
foreach ($person in $adobj){
$prop=$person.properties
$psbase=$person.psbase
$guid=$person.nativeguid
Write-host "$($prop.samaccountname)!$($prop.name)!$guid!$($prop.manager)"
}
I want my guid returned in this form:
{B5F47E28-C23E-4FBF-A0C1-8942FE171808}
From a posting here ( http://powershelllive.com/blogs/lunch/archive/2007/04/04/day-6-adsi-connecting-to-domains-computers-and-binding-to-objects.aspx ) I see there are 3 different forms of user object,
a processed DirectoryEntry
a native .NET DirectoryEntry
and a SearchResult
It seems to indicate that the .NET entry is the one I'm after, which I should be able to get by querying using LDAP (which I'm doing) to get a user object, and getting the psbase object from that user.
Can anyone shed some light on what I'm doing wrong?