I'm very new to VBScript. I have a need to list out the employee name and
account name for each user within a specific AD container. The following
link is to an article about a script that I used to get me started.
http://www.microsoft.com/technet/scriptcenter/resources/qanda/aug07/hey0802.mspx
I modified the script only slightly. Specifically, I removed the date
variables, modified the SELECT statement to return the sAMAccountName and
displayName, and to refer to my AD container and tree, and finally I
modified the output in from the Do Until loop. Here is my existing script
(with generic domain info):
***** Start *****
On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = _
"SELECT sAMAccountName, displayName FROM
'LDAP://ou=sales,dc=mycompany,dc=com' WHERE objectClass='user' "
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo objRecordSet.Fields("sAMAccountName").Value,
objRecordSet.Fields("displayName").Value
objRecordSet.MoveNext
Loop
***** End *****
The only problem is that the script seems to be returning machine accounts
in the results. I though that the objectClass='user' portion of the SELECT
statement would filter out all the noise and leave only the user accounts in
the results set.
Below is an example of the results. The first 3 lines are user accounts and
the last 3 are machine names.
az1853 Bopp, Betty
az2755 Baggins, Bilbo
az8541 Vader, Darth
SALES20$ null
SALES57$ null
SALES58$ null
Can someone tell me why the script is picking up more than just user
accounts?
--Tom