'On Error Resume Next
Const ForReading = 1
Dim arrADLook(4)
Dim arrUserADResult(4)
StartTime = Timer
count = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(".\" & "userlist.ini", ForReading)
Set objFile = objFSO.CreateTextFile(".\" & "
results.csv")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objFile.WriteLine "name,displayName,distinguishedName"
While Not objTextFile.AtEndOfStream
count = count + 1
strUserID = objTextFile.Readline
FindADUser(strUserID)
i = i + 1
If ((count mod 50) = 0) Then
EndTime2 = Timer
wscript.echo
count & " accounts processed in " & EndTime2 - StartTime & " seconds."
End If
Wend
EndTime = Timer
TotalTime = EndTime - StartTime
wscript.echo count & " accounts have been processed in " & TotalTime & " seconds."
objTextFile.Close
objConnection.Close
Sub FindADUser(UserID)
objCommand.CommandText = _
"<GC://dc=<your Domain>,dc=<root Domain>,dc=<dadada>,dc=com>;" & _
"(&(objectCategory=person)(objectClass=user)" & _
"(sAMAccountName=" & UserID & "));" & _
"sAMAccountName, distinguishedName, department;subtree"
Set objRecordSet = objCommand.Execute
If objRecordSet.RecordCount
> 1 Then
Wscript.Echo "More than 1 account found"
Else
While Not objRecordset.EOF
strUserDN=objRecordset.Fields("distinguishedName")
Set objItem = GetObject("LDAP://" & strUserDN)
objFile.WriteLine objItem.Get("name") & "," & _
objItem.Get("displayName") & "," & _
objRecordset.Fields("distinguishedName")
objRecordset.Fields("department")
'strdepartment = objItem.Get("department")
objRecordset.MoveNext
Wend
End If
End Sub
'
Good Morning guys!I need a script to locate bulk users from a text file and put it in a csv fileI know that Joe's tool would do this, but as I mentioned in my earliermails it can not be used in my organisation.:-(Have a wonderful Thursday!
Sincerely,J