Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Fetch NTDS directoryEntry parent?

Reply
 
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
Old 01-16-2007   #2 (permalink)
/\\/\\o\\/\\/ [MVP]


 
 

Re: Fetch NTDS directoryEntry parent?

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
Old 01-18-2007   #3 (permalink)
Bmack500


 
 

Re: Fetch NTDS directoryEntry parent?

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
Old 01-18-2007   #4 (permalink)
/\\/\\o\\/\\/ [MVP]


 
 

Re: Fetch NTDS directoryEntry parent?

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
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
Reply

Thread Tools


Similar Threads
Thread Forum
Push or Fetch Live Mail
using .Net DirectoryEntry to enumerate domains Vista networking & sharing
DirectoryEntry without using admin user: how to check if account'sexpired .NET General
Question when using System.DirectoryServices.DirectoryEntry PowerShell
Re: PSH: DirectoryEntry doesn't have Path Property??? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46