Option Explicit ' Enumerates Active Directory contents for logged on user's domain. N.B. By commenting the line 'DomainObj.Filter = Array( "user", "computer", "group" )' ' back in you may filter the objects listed. ' 6 Dec 2003 Using XML for output. ' 4 Dec 2000 Rolf Åberg Inspired by various scripts found on the Net. ' (c) Copyright 2000, 2003 Rolf Åberg, mailto:rolf.aberg@simplex.se. Free for all and all non-commercial use provided this line is retained. Const ForWriting = 2 ' Scripting.FileSystemObject.ForWriting. Const LdapPrefix = "LDAP://" Dim Fso ' Scripting.FileSystemObject. Dim OutputFile ' FileSystemObject.TextStream. Dim WshNetwork ' To get to the currently logged on user's information. Dim LdapObj ' Our LDAP connexion. Dim NameSpace ' Name spaces found in the LDAP object. Should be only one! Dim DomainObj ' An object in the domain, container or otherwise. Dim ContainerObjs() ' Collection of AD objects in a container. Dim AdObj ' Single AD object. Dim ObjDn ' Distinguished name for AD object. Dim RootDse ' Root DSE Information. Set Fso = CreateObject( "Scripting.FileSystemObject" ) On Error Resume Next Set WshNetwork = CreateObject( "WScript.Network" ) Set RootDse = GetObject( LdapPrefix & "RootDSE" ) Set OutputFile = Fso.OpenTextFile( RootDse.Get( "defaultNamingContext") & ".xml", ForWriting, True) OutputFile.WriteLine "" OutputFile.WriteLine "" OutputFile.WriteLine Space( 2 ) & "" OutputFile.WriteLine Space( 4 ) & "" & FormatDateTime( Now(), vbGeneralDate ) & "" OutputFile.WriteLine Space( 4 ) & "" & WshNetwork.UserName & "" OutputFile.WriteLine Space( 4 ) & "" & WshNetwork.UserDomain & "" OutputFile.WriteLine Space( 4 ) & "" & WshNetwork.ComputerName & "" OutputFile.WriteLine Space( 4 ) & "" OutputFile.WriteLine Space( 6 ) & "" & RootDse.Get( "serverName") & "" OutputFile.WriteLine Space( 6 ) & "" & RootDse.Get( "dnsHostName") & "" OutputFile.WriteLine Space( 6 ) & "" & RootDse.Get( "currentTime") & "" OutputFile.WriteLine Space( 6 ) & "" & RootDse.Get( "defaultNamingContext") & "" OutputFile.WriteLine Space( 6 ) & "" & RootDse.Get( "schemaNamingContext") & "" OutputFile.WriteLine Space( 6 ) & "" & RootDse.Get( "configurationNamingContext") & "" OutputFile.WriteLine Space( 6 ) & "" & RootDse.Get( "highestCommittedUsn") & "" OutputFile.WriteLine Space( 6 ) & "" OutputFile.WriteLine Space( 4 ) & "" Set LdapObj = GetObject( "LDAP:" ) For Each NameSpace in LdapObj ReDim ContainerObjs( 0 ) EnumAllContainers NameSpace.AdsPath, ContainerObjs ReDim Preserve ContainerObjs( UBound( ContainerObjs) - 1) ' We always add one extra so we have to remove it, too. Dim ContNum For ContNum = LBound( ContainerObjs ) To UBound( ContainerObjs ) Set DomainObj = GetObject( ContainerObjs( ContNum ) ) ObjDn = Mid( ContainerObjs( ContNum), Len( LdapPrefix ) + 1 ) OutputFile.WriteLine Space( 2 ) & "" ' DomainObj.Filter = Array( "user", "computer", "group" ) For Each AdObj In DomainObj OutputFile.WriteLine Space( 4 ) & "" Next OutputFile.WriteLine Space( 2 ) & "" Next Next OutputFile.WriteLine "" OutputFile.Close Private Sub EnumAllContainers( ContainerAdsPath, Containers() ) Dim ContObj Dim ChildObj Set ContObj = GetObject( ContainerAdsPath ) If Err.Number = 0 Then Containers( UBound( Containers)) = ContainerAdsPath ReDim Preserve Containers( UBound( Containers) + 1) For Each ChildObj In ContObj If (ChildObj.Class = "organizationalUnit") Or (ChildObj.Class = "builtinDomain") Or (ChildObj.Class = "container") Then EnumAllContainers ChildObj.AdsPath, Containers End If Next Else MsgBox ContObj.AdsPath & " " & ContObj.Class & " " & Err.Number End If End Sub Private Function CountOuLevel( ContainerAdsPath ) Dim TextPos Dim OusCounted OusCounted = 0 TextPos = 0 Do TextPos = InStr( TextPos + 1, ContainerAdsPath, "OU=") If TextPos > 0 Then OusCounted = OusCounted + 1 End If Loop While TextPos > 0 CountOuLevel = OusCounted End Function