View Single Post
Old 01-19-2007   #5 (permalink)
Bmack500


 
 

Re: Fetch NTDS directoryEntry parent?

Okay, Thanks
I'm confused on one thing - when you use the [adsi] statement, is that
just calling it a little more directly than using the .net framework? I
mean, does it bypass .net to go straight to the lower-level call?

Pardon if it's an ignorant question, I've only used high-level
languages.


/\/\o\/\/ [MVP] wrote:
> your welcome, glad it helped
>
> b.t.w. I can't test it but I think you can just use the property also :
>
> you can replace get_parent() by parent
>
> and shorten this :
>
> $de = new-object system.directoryservices.directoryentry("LDAP://" +
> > $objRootDse.ConfigurationNamingContext)

>
> to :
>
> $de = [adsi]LDAP://$($objRootDse.ConfigurationNamingContext)
>
> or even :
>
> $de = [adsi]""
>
> Greetings /\/\o\/\/
>
> "Bmack500" <brett.mack@gmail.com> wrote in message
> news:1169151501.429942.148880@l53g2000cwa.googlegroups.com...
> > This is working... Thanks for your help!
> >
> > Function SearchAD
> > {
> >
> > $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)
> > $gcSearcher = new-object
> > system.directoryservices.directorysearcher($de,$gcQuery)
> > $dclist = $dcSearcher.findall()
> > $gclist = $gcSearcher.findall()
> >
> > Foreach ($dc in $dclist)
> > {
> > $srchListItem = $dc.getDirectoryEntry()
> > $srchListItemParent = $srchListItem.psbase.get_parent()
> > $strServer = $srchListItemParent.serverReference
> > $objServer = New-Object
> > System.DirectoryServices.directoryentry('LDAP://' + $strServer)
> >
> > }
> > }
> >
> >
> > /\/\o\/\/ [MVP] wrote:
> >> you need to use psbase to get to the actual DE object see :
> >>
> >> http://mow001.blogspot.com/2006/09/p...directory.html
> >> http://mow001.blogspot.com/2006/09/p...ectory_29.html
> >>
> >> greetings /\/\o\/\/
> >>
> >> "Bmack500" <brett.mack@gmail.com> wrote in message
> >> news:1168976889.770325.95630@m58g2000cwm.googlegroups.com...
> >> > 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