Hi experts
I have just applied a new password policy, however a lot of users have their password never expires option ticked.
I need to untick this option for most of my users apart from systems accounts etc.
I know this has beed answered before however the script posted is not working for me
this is the line it fails on If strUserDN " " Then
i have exported all usernames as stated by the expert
the script im using is below
any ideas
the original question was
http://www.experts-exchange.com/Security/Q_21821175.htmlOption Explicit
Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
Dim lngFlag, objUser, objFSO, strFilePath, objFile
Dim strUserDN
' Specify the text file of user names.
strFilePath = "c:\MyFolder\UserList2.txt
"
' Open the file for read access.
Set objFSO = CreateObject("Scripting.Fi
leSystemOb
ject")
Set objFile = objFSO.OpenTextFile(strFil
ePath, 1)
' Read each line of the file, bind to the user object, and toggle
' "Password Never Expires" to false if needed.
Do Until objFile.AtEndOfStream
strUserDN = Trim(objFile.ReadLine)
If strUserDN " " Then
On Error Resume Next
Err.Clear
Set objUser = GetObject("LDAP://" & strUserDN)
If Err.Number 0 Then
Err.Clear
Wscript.Echo "User NOT found " & strUserDN
Else
lngFlag = objUser.Get("userAccountCo
ntrol")
If (lngFlag And ADS_UF_DONT_EXPIRE_PASSWD)
0 Then
lngFlag = lngFlag Xor ADS_UF_DONT_EXPIRE_PASSWD
objUser.Put "userAccountControl", lngFlag
objUser.SetInfo
If Err.Number 0 Then
Err.Clear
Wscript.Echo "Unable to set flag for " & strUserDN
End If
End If
End If
On Error GoTo 0
End If
Loop
' Clean up.
objFile.Close
Set objFile = Nothing
Set objFSO = Nothing
Set objUser = Nothing
Wscript.Echo "Done"
Start Free Trial