11.9. Script: Mass Admin Password Changer

What do you do when someone leaves your company that knows the administrator passwords for your systems? Do you go to all of your servers and change the passwords? You should. Do you periodically change all the administrator passwords on your systems by hand? That's where this script comes in handy. All you need is a text file that contains a list of servers, set the new password in the code, and run the script with an account that has administrative privileges on those servers. This way you can quickly change the administration password on a bunch of servers.

Here is the code:

Option Explicit On Error Resume Next Dim strServerList : strServerList = "c:\servers.txt" Dim strServerPass : strServerPass = "c:\pass.txt" Dim strServerFail : strServerFail = "c:\fail.txt" Dim strAdminAccount : strAdminAccount = "administrator" Dim strNewPassword : strNewPassword = "My!New!Password" Dim objFSO, objServersFile, objPassFile, objFailFile Set objFSO = CreateObject("Scripting.FileSystemObject") Set objServersFile = objFSO.OpenTextFile(strServerList) Set objPassFile = objFSO.CreateTextFile(strServerPass) Set objFailFile = objFSO.CreateTextFile(strServerFail) Do While not objServersFile.AtEndOfStream Dim strServer : strServer = objServersFile.ReadLine Dim objAdmin Set objAdmin = GetObject("WinNT://" & strServer & "/" _ & strAdminAccount & ",user") if Err then objFailFile.WriteLine strServer & " failed: " & Err.Description Err.Clear else objAdmin.SetPassword ...

Get Windows Server Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.