View Single Post
Old 01-16-2007   #1 (permalink)
Bmack500


 
 

Fetch NTDS directoryEntry parent?

How can I fetch the parent of a directoryentry object? Here's my code:

First, I use a directorysearch to get a list of the DC's ntds objects.
Then, I iterate through the collection.
But how can I fetch the $dc's parent object so that I can then get the
serverreference (a dn to the actual server)?


#Search
$objRootDse = New-Object
System.DirectoryServices.DirectoryEntry("LDAP://rootDSE")
$dcQuery = "(&(objectcategory=ntdsdsa))"
$gcQuery = "(&(objectcategory=ntdsdsa)(options=1))"
$de = new-object system.directoryservices.directoryentry("LDAP://" +
$objRootDse.ConfigurationNamingContext)
$dcSearcher = new-object
system.directoryservices.directorysearcher($de,$dcQuery)
$dclist = $dcSearcher.findall()

#Iterate

foreach ($dc in $dcList)
{
$objTEST = New-Object System.DirectoryServices.directoryentry
$objTEST = $dc.GetDirectoryEntry()
$objTest.distinguishedName
$props.cn
$myParent = New-Object System.DirectoryServices.directoryentry
$myParent = $objTest.parent
}

My System SpecsSystem Spec