Link to home
Start Free TrialLog in
Avatar of changjia
changjia

asked on

VBscirpt to list all user's DN into a txt file

Hi Guys,

I need a vbscript to read the root of my domain and query all user's DN value then write to a text file with each user's DN line by line.

Please help! Thanks in advance for your help!
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

change ROOT_LDAP to the ldap from which to get users DN.
const ROOT_LDAP = "cn=users,dc=soap,dc=com"
const USERS_FILE = "c:\temp\users.log"
Dim oConnection, oCommand, oRecordSet

Set oConnection = CreateObject("ADODB.Connection")
oConnection.Open "Provider=ADsDSOObject;"
Set oCommand = CreateObject("ADODB.Command")
oCommand.ActiveConnection = oConnection
oCommand.CommandText = "<LDAP://" & ROOT_LDAP & ">;(&(objectCategory=User));distinguishedName;subtree"
Set objRecordSet = oCommand.Execute

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
	line = line & objRecordSet.Fields("DistinguishedName") & vbNewLine
	objRecordSet.MoveNext
Loop

Set objFSO = CreateObject("Scripting.FileSystemObject")
set objFile = objFSO.CreateTextFile(USERS_FILE, 2)
objFile.Write line
objFile.Close
oConnection.Close
Set oRecordSet = Nothing
Set oCommand = Nothing
Set oConnection = Nothing

Open in new window

ADFIND Use the following command:
adfind -default -f objectClass=User -list distinguishedName

DSQUERY:  Use the following command.  Default limit is 100 (if you have less than 5000 users):
dsquery user -limit 5000
Avatar of changjia
changjia

ASKER

Hi Sedgwik,

I received error at line 12, charactor 1.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Tony Massa
Tony Massa
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
nevermind, I got that part fix, however,the output is partial, it doens't seem to grab all users in my domain, only 10%.
It looks like only retrive the first 1000 records, I want it all.. Thanks
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
samthing, only the first 1000 records were listed. Also, it seems not only retriving users, but also groups. I want users only. Thanks
this script checks for users only (see line 10)
i've tested it and it works fine, it logs 1215 users and only users.
can u post the exact script u running cause i'm not sure how it is possible

you are right, the script works, Thanks for your help!!
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.