![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||