Listing 1: PWcheck-change.bat :: BEGIN CALLOUT A @Echo Off @Title Password Check/Change Script Setlocal BEGIN COMMENT :: Set the location of the server input file. Spaces are allowed in :: the path. In the input file, place the information (i.e., server :: name, Administrator account name, and password) for :: each server on a separate line. Separate the server name, :: Administrator account name, and password with commas. END COMMENT Set ServerList=D:\AdminPasswordChanger\ServerList.csv BEGIN COMMENT :: Set the output file's location. Spaces are allowed in the path. END COMMENT Set Outputfile=D:\AdminPasswordChanger\PWlog.csv BEGIN COMMENT :: Set the Pspasswd tool's location. Spaces are allowed in the path. END COMMENT Set PspasswdLoc=\\Server1\PSTools\pspasswd.exe BEGIN COMMENT :: Set the Local tool's location. No spaces are allowed in the path. END COMMENT Set LocalLoc=\\Server1\Reskit\local.exe :: END CALLOUT A BEGIN COMMENT :: *** Configuration shouldn't be needed below this point. *** END COMMENT If /I '%1'=='-Change' Echo This script is about to change the passwords in the input list you have specified. If you want to launch the script in check mode, remove the -Change argument.&Set Change=1&Pause If /I Not '%1'=='-Change' Echo This script is about to check the passwords in the input list you have specified. No passwords will be changed - only checked. If you want to launch the script in a mode to change the passwords, use the -Change argument. &Set Change=0&Pause Echo %DATE%>"%Outputfile%" Echo %TIME%>>"%Outputfile%" Echo.>>"%Outputfile%" If "%Change%"=="1" Echo Script Run in PW Change Mode>>"%Outputfile%" If "%Change%"=="0" Echo Script Run in PW Check Mode – No passwords were changed>>"%Outputfile%" Echo.>>"%Outputfile%" Echo Servername,Admin Acct Name,PW,Result>>"%Outputfile%" :: BEGIN CALLOUT B For /f "tokens=1,2,3 usebackq delims=," %%i in ("%ServerList%") Do (Set Server=%%i) & (Set AdminName=%%j) & (Set Password=%%k) & (Call :Pingit) :: END CALLOUT B :: BEGIN CALLOUT C Echo Run complete! View Outputfile for results. Endlocal Goto :EOF :: END CALLOUT C :: BEGIN CALLOUT D BEGIN COMMENT :: Ping the server to see whether it's online. If offline, log error. END COMMENT :Pingit Echo Contacting %Server% For /F "tokens=1" %%i in ('Ping -n 1 -w 5000 %Server% ^| Find "Reply"') Do (Call :PWChange) & (Goto :skip) Echo %Server%,N/A,N/A,Offline!>>"%Outputfile%" Echo %Server% Offline! :Skip Goto :EOF BEGIN COMMENT :: If server is online, attempt password check or change. :: Log error if attempt fails. END COMMENT :PWChange If "%Change%"=="1" For /F "tokens=*" %%i in ('%PspasswdLoc% \\%Server% %AdminName% %Password%') Do Echo %Server%,%AdminName%,"%Password%",PW Change Success,>>"%Outputfile%"&Goto :Last If "%Change%"=="0" Net Use \\%Server%\IPC$ /D >NUL 2>NUL If "%Change%"=="0" Net Use \\%Server%\IPC$ "%Password%" /USER:%Server%\%AdminName%&& Echo %Server%,%AdminName%,%Password%,PW Checked and Confirmed>>"%Outputfile%" && Goto :Last :: END CALLOUT D :: BEGIN CALLOUT E Set Aname= For /F "tokens=*" %%i in ('%LocalLoc% Administrators \\%Server% ^| Find /I "\%AdminName%"') Do (Set Aname=%%i) If Not Defined Aname Echo %Server%,%AdminName%,N/A,User account not found>>"%Outputfile%"&Goto :Last Echo %Server%,%AdminName%,%Password%,PW Check/Change Failure>>"%Outputfile%" :: END CALLOUT E :Last Goto :EOF