'==========================================================================
'
' NAME: ResetPasswordFromList.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE : 3/4/2005
'
' COMMENT: reads a list of users and resets the passwords.
'
'==========================================================================
On Error Resume Next
Dim objuser, newpass, UserLDAP, lngFlag
Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
'open the file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")
set WSHShell = wscript.createObject("wscript.shell")
'open the data file
Set oTextStream = oFSO.OpenTextFile("ulist.txt")
'make an array from the data file
UserList = Split(oTextStream.ReadAll, vbNewLine)
'close the data file
oTextStream.Close
For Each oUser In UserList
Set objuser = "LDAP://" & SearchDistinguishedName(oUser)
newpass = "NewPasswordHere"
'Require User to change password at next logon? Y Or N
changenextlogin = "Y"
objUser.SetPassword newpass
If changenextlogin <> "N" Then
objUser.Put "PwdLastSet", 0
End If
objUser.SetInfo
lngFlag = objUser.Get("userAccountControl")
If (lngFlag And ADS_UF_DONT_EXPIRE_PASSWD) <> 0 Then
lngFlag = lngFlag Xor ADS_UF_DONT_EXPIRE_PASSWD
objUser.Put "userAccountControl", lngFlag
objUser.SetInfo
End If
Next
Public Function SearchDistinguishedName(ByVal vSAN)
' Function: SearchDistinguishedName
' Description: Searches the DistinguishedName for a given SamAccountName
' Parameters: ByVal vSAN - The SamAccountName to search
' Returns: The DistinguishedName Name
' Thanks to Tek-Tips user Kob3 for this function.
Dim oRootDSE, oConnection, oCommand, oRecordSet
Set oRootDSE = GetObject("LDAP://rootDSE")
Set oConnection = CreateObject("ADODB.Connection")
oConnection.Open "Provider=ADsDSOObject;"
Set oCommand = CreateObject("ADODB.Command")
oCommand.ActiveConnection = oConnection
oCommand.CommandText = "<LDAP://" & oRootDSE.get("defaultNamingContext") & _
">;(&(objectCategory=User)(samAccountName=" & vSAN & "));distinguishedName;subtree"
Set oRecordSet = oCommand.Execute
On Error Resume Next
SearchDistinguishedName = oRecordSet.Fields("DistinguishedName")
On Error GoTo 0
oConnection.Close
Set oRecordSet = Nothing
Set oCommand = Nothing
Set oConnection = Nothing
Set oRootDSE = Nothing
End Function