>Hi.
>I have a domain with several OUs.
>I need a script to export in excel the users of all OUs.
>any idea? :(
Here is a begriming:
On Error Resume Next
Dim objConnection, objCommand, objRootDSE, strDNSDomain
Dim strFilter, strQuery, objRecordSet
dim fso, contents, writefile
set fso = CreateObject("Scripting.FileSystemObject")
set writefile = fso.CreateTextFile("C:\TEMP\SortADU.tm1", 2)
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOOBject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"
strFilter = "(&(objectCategory=person)(objectClass=user))"
strAttributes = "distinguishedName"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 99999
objCommand.Properties("Timeout") = 300
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strDN = objRecordSet.Fields("distinguishedName")
ouPath = Split(strDN, ",")
ouLen = Len(ouPath(1))
ouNameLen = ouLen - 3
ouc = Left (ouPath(1), 3)
oun = Right(ouPath(1), ouNameLen)
contents = """" & ouc & oun & """;""" & strDN & """"
writefile.writeLine contents
objRecordSet.MoveNext
Loop
objConnection.Close
writefile.close
Set objConnection = Nothing
Set objCommand = Nothing
Set objRootDSE = Nothing
Set objRecordSet = Nothing
I would sort the "C:\TEMP\SortADU.tm1" file
and create a csv of the output.
Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com
http://www.jsifaq.com
>My antivirus says that this script is a trojan,
>Trojan-Dropper.VBS.Bomgen.h........................
Your anti-virus is sadly mistaken.
Just looking at it you can see that it isn't.