Crumpled Thoughts

January 27th, 2006

Mass Change Local Admin Password on Windows Domain Computers

Posted by Chris in Windows, Sysadmin

Yesterday I was at a client’s site and was tasked with changing the password for the local administrator account on approximately 200 MS Windows domain computers. Typically if I have to change the local admin password on a few domain computers I’ll just use the computer management MMC snapin, connect to a remote computer, change the password, lather – rinse – repeat. This would take forever though to do on 200 computers.

I came across a Visual Basic Script file which allowed me to complete the task in about 15 minutes. I just had to create a text file with the netbois computer names of each machine I wanted to change the password on, then run one command. This little script is going to come in handy. I found it published here, at VisualBasicScript.com.

There were a couple of issues. If one of the computers is powered off, or otherwise unavailable on the network the script will halt. To do 200 computers I had the script abort about 10 times and I’d deleted the completed computers and the problem computer names from the text file and start it again. Still saved me a ton of time though. Of course you have to run this as a domain user which has administrative rights on domain computers.

USAGE:

cscript local_admin_chpw.vbs password input.txt

Here’s the script:

'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 3.1
'
' NAME: Local Admin Change Password
'
' AUTHOR: Kirrilian
' Date  : 2/22/2005
'
' COMMENT:
'        usage: cscript local_admin_chpw.vbs password input.txt
'        the input file should be a list of machines you want to change the
'        password on. One hostname per line.
'==========================================================================

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments.Unnamed

'InputFile = "C:input.txt"
MyDate = Replace(Date, "/", "-")
OutputFile = "C:output-" & mydate & ".txt"

If Not objArgs.Count = 0 Then
    If objArgs.Count = 2 Then
        password = WScript.Arguments.Item(0)
        InputFile = WScript.Arguments.Item(1)
        If fso.FileExists(InputFile) Then
            Set txtStreamIn = fso.OpenTextFile(InputFile)
            Set txtStreamOut = fso.OpenTextFile(OutputFile, 2, True)
            Do While Not (txtStreamIn.AtEndOfStream)
                strComputer = txtStreamIn.ReadLine
                chpw strComputer, password
            loop
        Else
            WScript.Echo "Input file doesnt exist."
            usage
        End if
    Else
        usage
    End if
Else
    usage
End If

Sub usage()
    WScript.Echo "Usage: cscript local_admin_chpw.vbs password input.txt"
    WScript.Echo "NOTE: if your password has special characters in it you will have to enclose it in quotes"
End Sub 'usage

Sub printOut (data)
    WScript.Echo data
    txtStreamOut.writeline data
End Sub 'printOut

Sub chpw (computer,password)
    Set objUser = GetObject("WinNT://" & computer & "/Administrator, user")
    printOut "changing the password on " & computer & " to " & password
    objUser.SetPassword password
    objUser.SetInfo
End Sub 'chpw

Leave a reply

:mrgreen: :neutral: :twisted: :shock: :smile: :???: :cool: :evil: :grin: :oops: :razz: :roll: :wink: :cry: :eek: :lol: :mad: :sad: