keybrdcowboy
IS-IT--Management
Would appreciate any help you can give here. I am trying to loop through all our users in AD without feeding in usernames via a text file. Below is my code. When I run the code, it only counts 8xx users. We have a little over 28xxx user accounts in our domain. Can anyone help explain why this doesn't work? Thanks for any input.
Code:
Option Explicit
Dim oConn, oRS, oSid, strServerName, strGALEmail, strGALLastName, strGALFirstName, strGALDisplayName, strGALDescription, strLastChanged
Dim strGALCity, strGALOffice, strDomain, strGALZip, strGALState, strGALStreet, strGALTelNum, strGALTitle, strGALRank, oFSO, readFile
Dim outFile, iUpperBound, strUserName, oRootDSE, oConnection, oCommand, oRecordSet, strConnect, UserObj, strAD, strGoodCount
Dim strLogPath, oShell, strEmailLen, strSid, strTotalCount, strOKCount, strEmail, strQuery, strErrorControl, outFile2, strUser
Dim strChangedToday, strDidNotChangeToday
Const ForAppending = 8
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.Shell")
strLogPath = oShell.ExpandEnvironmentStrings("%USERPROFILE%")
' Sets up the script to use a log file
If oFSO.FileExists(strLogPath & "\desktop\totalUsers.csv") = True Then
Set outFile = oFSO.OpenTextFile(strLogPath & "\desktop\totalUsers.csv", ForAppending)
Else
Set outFile = oFSO.CreateTextFile(strLogPath & "\desktop\totalUsers.csv", True)
End If
strTotalCount = 0
Set oRootDSE = GetObject("LDAP://rootDSE")
Set oConnection = CreateObject("ADODB.Connection")
oConnection.Open "Provider=ADsDSOObject;"
Set oCommand = CreateObject("ADODB.Command")
oCommand.ActiveConnection = oConnection
oCommand.Properties ("Cache Results") = False
oCommand.Properties ("Size Limit") = 100000
oCommand.Properties ("Asynchronous") = True
oCommand.CommandText = "<LDAP//" & oRootDSE.get("defaultNamingContext") & ">;(&(objectCategory=person)(objectClass=user));name;subtree"
Set oRecordSet = oCommand.Execute
While Not oRecordSet.EOF
'outFile.WriteLine oRecordSet.Fields("name")
strTotalCount = strTotalCount + 1
oRecordSet.MoveNext
Wend
outFile.WriteLine "Total Count of Records: " & strTotalCount
WScript.Echo "Done"