Using VBScript to Export All Objects in an OU (this OU is called Marketing)
Use a text editor such as Notepad to create a VBScript program. The script searches the Marketing OU and creates a text file that lists all of the user objects and a subset of their attributes.
To create the export script
Copy the following text into your text editor:
'Initialize global variables
Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
Set OutPutFile = FileSystem.CreateTextFile("marketing.txt", True)
Set FileSystem = Nothing
Set oContainer = Nothing
For Each oUser In oCont
Select Case LCase(oUser.Class)
If Not IsEmpty(oUser.distinguishedName) Then
OutPutFile.WriteLine "dn: " & oUser.distinguishedName
If Not IsEmpty(oUser.name) Then
OutPutFile.WriteLine "name: " & oUser.Get ("name")
'need to do this because oUser.name would get back the Relative
Distinguished name (i.e. CN=Jo Brown)
If Not IsEmpty(oUser.st) Then
OutPutFile.WriteLine "st: " & oUser.st
If Not IsEmpty(oUser.streetAddress) Then
OutPutFile.WriteLine "streetAddress: " & oUser.streetAddress
Case "organizationalunit" , "container"
Save the file as Export.vbs.
At the command prompt type export.vbs and press Enter. This creates a file named Marketing.txt, which contains a list of users and some of their attributes, such as distinguished name, name, state, and street address.
With appropriate modification, this script can be used with any application that supports COM and Visual Basic technologies. Such applications include Microsoft Visual Basic, Microsoft Excel, and Microsoft Access. Scripting can also be hosted by Internet Explorer and Internet Information Services 5.0, which is part of Windows 2000 Server.