Ok, guys I might have spoken too soon. The script that I have works only if the number of users in the specified OU is less than 50. When I try to use the script on an OU that has thousands of users then it only updates half of the record. Can someone please look at my script and tell me what I am missing?
'Enumeration When set, the password will not expire on this account
Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
'Declare variables that will be used to write out status
Dim OutPutFile
Dim FileSystem
'Initialize the variables
Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
Set OutPutFile = FileSystem.CreateTextFile("PasswordStatus-output.txt", True)
'create a connection to AD using AD ADO (Active X Data Objects) provider
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
'A query to get users full name from the specified OU
objCommand.CommandText = "SELECT distinguishedName FROM 'LDAP://OU=CompanyUsers,OU=Allusers,DC=company,DC=com' WHERE objectCategory='user'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strDN = objRecordSet.Fields("distinguishedName").Value
objRecordSet.MoveNext
Set objUser = GetObject ("LDAP://" & strDN)
intUAC = objUser.Get("userAccountControl")
If ADS_UF_DONT_EXPIRE_PASSWD AND intUAC Then
OutPutFile.WriteLine objUser.Name & ": already enabled"
Else
objUser.Put "userAccountControl", intUAC XOR ADS_UF_DONT_EXPIRE_PASSWD
objUser.SetInfo
OutPutFile.WriteLine objUser.Name & ": Password never expires is now enabled"
End If
OutPutFile.WriteLine
Loop
Wscript.Echo "Done"
"Behind every great fortune there lies a great crime", Honore De Balzac