![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | Exctracting OU and parent OU name from Active Directory Hi there I want to make a script that pulls out the names of all OUs and their parent OUs to a text file. From various sources on the web, I managed to gather enough clues to make this short script: Filename = "parent.txt" Const Writable = 2 Set FileObject = CreateObject("Scripting.FileSystemObject") Set OutPutFile = FileObject.OpenTextFile(filename, Writable, True) Set currentou = GetObject("ldap://ou=subtest, ou=test, dc=domain, dc=com") Set ouParent = GetObject(currentou.Parent) OutPutFile.write ouParent.ou & ";" OutPutFile.write currentou.ou This script creates the file "parent.txt" and writes the parent of the subtest ou and the name of the subtest ou itself like this: test;subtest However I need it to output this name;parent for all OUs within the test OU, not just itself. So I gather I have to somehow loop through all OUs in the structure and make the script return ouparent.ou and current.ou for all of them so the file ends up something like this test;subtest subtest;west subtest;east subtest;north north;marketing You get the idea, I hope. However, I don't seem to be able to find out how I loop through an OU structure. The closest I've gotten was to loop through members of a group, but that wasn't exactly what I wanted. Any suggestions? Thanks in advance Ib |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Exctracting OU and parent OU name from Active Directory I made it work actually Disregard this post |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Exctracting OU and parent OU name from Active Directory "Ib Schrader" <ibschrader@xxxxxx> wrote in message news:%23uyBxDJ%23IHA.4816@xxxxxx Quote: >I made it work actually > > Disregard this post > recursive routine to enumerate the child OU's. You are starting at the lowest level and working up to the domain (or top level OU). A recursive routine is still the most straightforward method (to handle any level of nesting), but you need to test the class of the parent object to determine when you have reached the domain. For example: ========= Option Explicit Dim objOU Set objOU = GetObject("ldap://ou=subtest,ou=test,dc=domain,dc=com") Call EnumOUs(objOU) Sub EnumOUs(objChild) Dim objParent Set objParent = GetObject(objChild.Parent) If (objParent.Class = "organizationalUnit") Then Wscript.Echo objChild.ou & ";" & objParent.ou Call EnumOUs(objParent) Else Wscript.Echo objChild.ou & ";" & objParent.distinguishedName End If End Sub -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| active directory | PowerShell | |||
| Active Directory | Vista General | |||
| Active Directory | Vista networking & sharing | |||
| Active Directory | PowerShell | |||
| Get parent directory | PowerShell | |||