RichGK
RichGK

Reputation: 560

How can I get this script to output the distinguished name?

I've added what I thought the distinguished name should be 'dn' but it comes back blank. The givenname and sn fields are returned OK.

Thanks.

$Dom = 'LDAP://DC=oakland;DC=local'
$Root = New-Object DirectoryServices.DirectoryEntry $Dom
$i=0
$selector = New-Object DirectoryServices.DirectorySearcher
$selector.SearchRoot = $root

$adobj= $selector.findall() | where {$_.properties.objectcategory -match "CN=Person"}

foreach ($person in $adobj){
    $prop=$person.properties
    $i++
    Write-Host "$($prop.givenname) $($prop.sn) $($prop.dn)" 
}

"Total $i"

Upvotes: 0

Views: 256

Answers (1)

CB.
CB.

Reputation: 60976

You seem to be looking for $prop.distinguishedname.

Upvotes: 1

Related Questions