I have a top level OU with 4 nested OU's and would like my script to search all of the OU's when running the script. I've seen ADO being suggested but that seems like overkill for what I'm trying to do. How can I make the following recursive (I want all OU's under site1 to be included)? ------------------------------------------------------------------------------------------------- ' Bind to OU, using the Distinguished Name of the OU. Set objOU = GetObject("LDAP://ou=site1,dc=company,dc=com") ' Filter on user objects. objOU.Filter = Array("user") ' Enumerate users. For Each objUser In objOU Do this and that and the other thing..... ------------------------------------------------------------------------------------------------- Thanks, D
wrote in message news:54aba935-6ead-4d5f-abcc-3480a6a59154@i29g2000prf.googlegroups.com... >I have a top level OU with 4 nested OU's and would like my script to > search all of the OU's when running the script. I've seen ADO being > suggested but that seems like overkill for what I'm trying to do. How > can I make the following recursive (I want all OU's under site1 to be > included)? > > ------------------------------------------------------------------------------------------------- > ' Bind to OU, using the Distinguished Name of the OU. > Set objOU = GetObject("LDAP://ou=site1,dc=company,dc=com") > > ' Filter on user objects. > objOU.Filter = Array("user") > > ' Enumerate users. > For Each objUser In objOU > Do this and that and the other thing..... > ------------------------------------------------------------------------------------------------- A recursive subroutine should work: ========== Dim objOU ' Bind to parent OU object. Set objOU = GetObject("LDAP://ou=site1,dc=company,dc=com") Call EnumUsers(objOU) Sub EnumUsers(objParent) ' Recursive sub to enumerate users. Dim objChild ' Filter on user objects in OU. objParent.Filter = Array("user") ' Enumerate users. For Each objUser In objParent Wscript.Echo objUser.sAMAccountName Next ' Filter on child OU's. objParent.Filter = Array("organizationalUnit") ' Enumerate child OU's. For Each objChild In objParent Call EnumUsers(objChild) Next End Sub -- Richard Mueller Microsoft MVP Scripting and ADSI Hilltop Lab - http://www.rlmueller.net --