+ 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
    160
    Thank Post
    119
    Thanked 4 Times in 4 Posts
    Rep Power
    11

    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. #2

    Join Date
    Mar 2008
    Location
    Surrey
    Posts
    2,168
    Thank Post
    98
    Thanked 319 Times in 261 Posts
    Blog Entries
    4
    Rep Power
    113
    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
    '*****************************************************************************************

  3. #3

    mattx's Avatar
    Join Date
    Jan 2007
    Posts
    9,240
    Thank Post
    1,058
    Thanked 1,068 Times in 625 Posts
    Rep Power
    740
    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 !!!

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

  5. #5
    rh91uk's Avatar
    Join Date
    Sep 2008
    Location
    UK
    Posts
    877
    Thank Post
    137
    Thanked 132 Times in 114 Posts
    Rep Power
    36
    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.

  6. #6
    stariq's Avatar
    Join Date
    Feb 2008
    Location
    Birmingham
    Posts
    190
    Thank Post
    113
    Thanked 18 Times in 16 Posts
    Rep Power
    17
    Another one for wisesoft Account Management

    Saved us sssooo much hassle!

    ST

  7. #7
    timbo343's Avatar
    Join Date
    Dec 2005
    Location
    Leeds/York area, North Yorkshire
    Posts
    3,051
    Thank Post
    308
    Thanked 293 Times in 203 Posts
    Rep Power
    120

  8. #8

    SpuffMonkey's Avatar
    Join Date
    Jul 2005
    Posts
    2,249
    Thank Post
    55
    Thanked 280 Times in 187 Posts
    Rep Power
    134
    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

  9. #9

    john's Avatar
    Join Date
    Sep 2005
    Location
    London
    Posts
    10,363
    Thank Post
    1,500
    Thanked 1,054 Times in 923 Posts
    Rep Power
    303
    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

  10. #10
    rh91uk's Avatar
    Join Date
    Sep 2008
    Location
    UK
    Posts
    877
    Thank Post
    137
    Thanked 132 Times in 114 Posts
    Rep Power
    36
    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. Replies: 4
    Last Post: 6th May 2014, 07:25 PM
  2. bulk password reset
    By Jonny_sims in forum Windows
    Replies: 10
    Last Post: 26th September 2011, 10:12 PM
  3. Replies: 15
    Last Post: 28th August 2009, 09:55 AM
  4. Bulk password reset to a default?
    By MGSTech in forum Windows
    Replies: 6
    Last Post: 2nd September 2008, 07:34 PM
  5. Replies: 14
    Last Post: 27th March 2008, 04: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
  •