+ Post New Thread
Results 1 to 10 of 10
Scripts Thread, Bulk password reset script in Coding and Web Development; Hello, Does anybody have a script which will allow me to reset multiple users passwords all in one go? Thanks....
  1. #1
    lafleur1977's Avatar
    Join Date
    May 2009
    Location
    Lancashire
    Posts
    86
    Thank Post
    42
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Bulk password reset script

    Hello,

    Does anybody have a script which will allow me to reset multiple users passwords all in one go?

    Thanks.

  2. IDG Tech News

  3. #2

    Join Date
    Mar 2008
    Location
    Woking
    Posts
    2,094
    Blog Entries
    4
    Thank Post
    86
    Thanked 302 Times in 249 Posts
    Rep Power
    98
    I tend to use one developed by Matthew Hull. I found it somewhere on the internet, but can't remember where. It'll reset all the passwords for users in a specific OU rather than just all passwords at once. The script itself is here:

    Code:
    'Created by Matthew Hull 5/20/04
    'Last modified 9/9/05
    'Version 1.01
    'This script will reset the passwords for all users in a specified OU.
    'You can have it assign the same password to all users or generate a 
    'random password for each user.
    'Version History
    '~~~~~~~~~~~~~~~
    'Version 1.01 - Improved error detection.
    'Version 1.0 - First version of this script released.
    Option Explicit
    On Error Resume Next
    Dim intPasswordLength, strOU, objUser, objOU, objADHelper, intRandomNumber, txtLogFile
    Dim strPassword, bolForceChange, strLogFile, objFSO, bolNeverExpire
    '*****************************************************************************************
    strOU = "Script Test" 'Name of the OU that contains the users you want to modify
    strLogFile = "C:\Password Change Log.csv" 'Location and name of the log
    bolForceChange = False 'Set True to have the user to change their password on next logon
    bolNeverExpire  = True 'Set True to set the password never to expire
    intPasswordLength = 8 'Set the length of the random password
    strPassword = "" 'Set generic password for all users if inPasswordLength = 0
    '*****************************************************************************************
    'Exit the script if bolForceChange and bolNeverExpire are set to true.
    If bolForceChange And bolNeverExpire Then
       MsgBox "bolForceChange and bolNeverExpire cannot both be True." & vbCRLF & _
       "The script will now exit.",vbCritical,"Error"
       WScript.Quit
    End If
    'Create the OU Helper object and get the OU object using the OU Helper object   
    Set objADHelper = CreateObject("ADHelper.wsc")
    'Exit if the ADHelper object isn't installed
    If Err Then
       MsgBox "You must have ADHelper 1.0 or later installed on your PC.  " & _
          "The script will now exit.",vbCritical,"Network Missing"
       Err.Clear
       WScript.Quit
    End If
    'Use the ADHelper object to create the OU object
    Set objOU = objADHelper.OUObject(strOU)
    'Exit if the there is an error creating the OU object
    If Err Then
       MsgBox "There is a problem with your strOU setting, OU Not Found" & _
          "The script will now exit.",vbCritical,"OU Not Found"
       Err.Clear
       WScript.Quit
    End If
    'Create the File System Object, and use it to create the log file
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set txtLogFile = objFSO.CreateTextFile(strLogFile)
    txtLogFile.WriteLine("Display Name,User Name,Password")
    If Err Then ErrorMessage
    'Loop through each user and set the password
    For Each objUser in objOU
       If intPasswordLength <> 0 Then
          strPassword = GeneratePassword(intPasswordLength)
       End If
       If objUser.class = "user" Then
          Call SetPassword(objUser, strPassword, bolForceChange, bolNeverExpire)
          txtLogFile.WriteLine("""" & objUser.DisplayName & """," & _
             objUser.SamAccountName & "," & strPassword)
       End If   
    Next
    MsgBox "The passwords have been reset.",vbOkOnly,"Done"
    'Close the log file
    txtLogFile.Close
    '*****************************************************************************************
    Sub SetPassword(objUser,strPassword,bolForceChange,bolNeverExpire)
       Dim intUAC
       objUser.SetPassword(strPassword)
       objUser.SetInfo
       objUser.Put "UserAccountControl", 512 ' Normal Account
       objUser.SetInfo
       If bolForceChange Then
          objUser.Put "pwdLastSet", 0 'User must change password at next login          
          objUser.SetInfo        
       End If
       intUAC = 512
       If bolNeverExpire Then
          intUAC = intUAC + 65536
       End If
       objUser.Put "UserAccountControl", intUAC
       objUser.SetInfo
    End Sub
    '*****************************************************************************************
    Function GeneratePassword(intLength)
       Dim intIndex, intRandomNumber
       Randomize Timer
       For intIndex = 1 to intLength
          intRandomNumber = Int(2 * Rnd)   
          Select Case intRandomNumber
             Case 0 
                intRandomNumber = Int(10 * Rnd) + 48 '0-9
             Case 1
                intRandomNumber = Int(26 * Rnd) + 97 'a-z
          End Select   
          GeneratePassword = GeneratePassword & Chr(intRandomNumber)
       Next
    End Function
    '*****************************************************************************************
    Sub ErrorMessage
       MsgBox "There was an error detected." & vbCRLF & vbCRLF & "Error Description: " & _
          Err.Description & vbCRLF & "Error Number: " & Err.Number & vbCRLF & vbCRLF & _
          "The script will now exit...",vbCritical,"Error"
       WScript.Quit
    End Sub
    '*****************************************************************************************

  4. #3

    mattx's Avatar
    Join Date
    Jan 2007
    Posts
    8,472
    Thank Post
    889
    Thanked 890 Times in 532 Posts
    Rep Power
    596
    Quote Originally Posted by lafleur1977 View Post
    Hello,

    Does anybody have a script which will allow me to reset multiple users passwords all in one go?

    Thanks.
    I just pipe group names to a text file and then create a batch with:

    Code:
    net user [ USERNAME ] [ NEWPASSWORD ]
    Depending on how many groups you have will obvioulsy depend on how long it takes !!!

  5. #4
    lafleur1977's Avatar
    Join Date
    May 2009
    Location
    Lancashire
    Posts
    86
    Thank Post
    42
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    thanks for your help guys, i will give them ago :]

  6. #5
    rh91uk's Avatar
    Join Date
    Sep 2008
    Location
    UK
    Posts
    823
    Thank Post
    133
    Thanked 121 Times in 104 Posts
    Rep Power
    30
    http://www.wisesoft.co.uk/software/a...t/default.aspx

    This is great, I use it to acomplish the exact same thing you want to do.

  7. #6

    Join Date
    Feb 2008
    Location
    Birmingham
    Posts
    183
    Thank Post
    108
    Thanked 15 Times in 14 Posts
    Rep Power
    0
    Another one for wisesoft Account Management

    Saved us sssooo much hassle!

    ST

  8. #7
    timbo343's Avatar
    Join Date
    Dec 2005
    Location
    Leeds/York area, North Yorkshire
    Posts
    1,730
    Thank Post
    76
    Thanked 85 Times in 72 Posts
    Rep Power
    41

  9. #8
    SpuffMonkey's Avatar
    Join Date
    Jul 2005
    Posts
    1,851
    Thank Post
    32
    Thanked 185 Times in 119 Posts
    Rep Power
    86
    Quote Originally Posted by mattx View Post
    I just pipe group names to a text file and then create a batch with:

    Code:
    net user [ USERNAME ] [ NEWPASSWORD ]
    Depending on how many groups you have will obvioulsy depend on how long it takes !!!
    This is a useful bodge - specially combined with Excel - so you can just drag the commands down a column in front of the imported logins

  10. #9

    john's Avatar
    Join Date
    Sep 2005
    Location
    Yorkshire
    Posts
    9,144
    Thank Post
    979
    Thanked 739 Times in 651 Posts
    Rep Power
    199
    I use http://www.wisesoft.co.uk/software/p...d_control.aspx from Wisesoft for my bulk resetting needs, works very well, infact I use a lot of the Wise Soft tools they are really good

  11. #10
    rh91uk's Avatar
    Join Date
    Sep 2008
    Location
    UK
    Posts
    823
    Thank Post
    133
    Thanked 121 Times in 104 Posts
    Rep Power
    30
    Quote Originally Posted by SpuffMonkey View Post
    This is a useful bodge - specially combined with Excel - so you can just drag the commands down a column in front of the imported logins
    Agreed - Excel has just saved us a lot of time here!

SHARE:
+ Post New Thread

Similar Threads

  1. bulk password reset
    By Jonny_sims in forum Windows
    Replies: 10
    Last Post: 26th September 2011, 10:12 PM
  2. Replies: 15
    Last Post: 28th August 2009, 09:55 AM
  3. Bulk password reset to a default?
    By MGSTech in forum Windows
    Replies: 6
    Last Post: 2nd September 2008, 07:34 PM
  4. Replies: 3
    Last Post: 14th August 2008, 12:05 PM
  5. Replies: 14
    Last Post: 27th March 2008, 05:57 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •