export account details from an OU
Hey guys I need some urgent help from you all. Due to some reasons I need to export a data of my OU to CSV format. Let me tell you that this OU also contains some more OU’s which I also need to be exported. As I have never done this before, can anyone please tell me what the easiest way for doing the same is? Also can somebody please tell if I can choose only one OU or everything included in this OU can be exported?
Many thanks.
RE: export account details from an OU
Yes, it is possible. Just try out the following (queries all users under the "sales" OU and sub-OUs):
On Error Resume Next
Quote:
Const ADS_SCOPE_SUBTREE = 2
Const FOR_WRITING = 2
outFile = ".\Users.csv"
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
Set objFSO = CreateObject("Scripting.FileSystemObject")
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = _
"SELECT Name FROM 'LDAP://ou=sales,dc=fabrikam,dc=com' WHERE
objectCategory='user'"
Set objRecordSet = objCommand.Execute
Set objOut = objFSO.CreateTextFile(outFile, FOR_WRITING)
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo objRecordSet.Fields("Name").Value
objOut.Writeline objRecordSet.Fields("Name").Value
objRecordSet.MoveNext
Loop
Re: export account details from an OU
Thank you very much for the help Chapal but as being the first time, can you please also tell me where do i need to run this query?
Thanks again.
Re: export account details from an OU
There is no specific place to run this, you can simply run it on any workstations authenticated to the domain. It will create a file named Users.csv. But the best way I can suggest you is to run this in a command prompt with the cscript host. For example, if
the script is saved in the file GetUsers.vbs (the file must have the *.vbs extension), you can use the following command at a command prompt:
cscript GetUsers.vbs