I have zero knowledge on how to make a vbscript. I found the code below from here.
' Get OU
'
strOU = "OU=Users,DC=DOMAIN.BIZ,DC=com"
' Create connection to AD
'
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
' Create command
'
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
' Execute command to get all users in OU
'
objCommand.CommandText = _
"<LDAP://" & strOU & ">;" _
& "(&(objectClass=user)(objectCategory=person));" _
& "adspath,distinguishedname,sAMAccountName;subtree"
Set objRecordSet = objCommand.Execute
' Show info for each user in OU
'
Do Until objRecordSet.EOF
' Show required info for a user
'
WScript.Echo objRecordSet.Fields("adspath").Value
WScript.Echo objRecordSet.Fields("distinguishedname").Value
WScript.Echo objRecordSet.Fields("sAMAccountName").Value
' Move to the next user
'
objRecordSet.MoveNext
Loop
' Clean up
'
objRecordSet.Close
Set objRecordSet = Nothing
Set objCommand = Nothing
objConnection.Close
Set objConnection = Nothing
It's not what I really wanted but at least it's something I could try to work on. I'm running it on a client pc using Windows 7.
I fixed some minor stuff like the multi line. Now it always throw an error on Set objRecordSet = objCommand.Execute, saying The specified domain either does not exist or could not be contacted. I'm not using an admin account.
From the comments on the page, it seemed to work for them.
' Get OU
'
strOU = "OU=Users,DC=DOMAIN.BIZ,DC=com"
' Create connection to AD
'
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
' Create command
'
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
' Execute command to get all users in OU
'
objCommand.CommandText = _
"<LDAP://" & strOU & ">;" _
& "(&(objectClass=user)(objectCategory=person));" _
& "adspath,distinguishedname,sAMAccountName;subtree"
Set objRecordSet = objCommand.Execute
' Show info for each user in OU
'
Do Until objRecordSet.EOF
' Show required info for a user
'
WScript.Echo objRecordSet.Fields("adspath").Value
WScript.Echo objRecordSet.Fields("distinguishedname").Value
WScript.Echo objRecordSet.Fields("sAMAccountName").Value
' Move to the next user
'
objRecordSet.MoveNext
Loop
' Clean up
'
objRecordSet.Close
Set objRecordSet = Nothing
Set objCommand = Nothing
objConnection.Close
Set objConnection = Nothing
It's not what I really wanted but at least it's something I could try to work on. I'm running it on a client pc using Windows 7.
I fixed some minor stuff like the multi line. Now it always throw an error on Set objRecordSet = objCommand.Execute, saying The specified domain either does not exist or could not be contacted. I'm not using an admin account.
From the comments on the page, it seemed to work for them.