Pages

Sunday, October 13, 2013

Reset Password for Local Administrator account on multiple computers Remotely.

Here is a simple batch script which can be used to Reset Password for Local Administrator account on multiple computers Remotely.
This script uses pspasswd.exe utility which can be found in sysinternals tools.

Step 1:- Create a notepad file and copy the below lines of code (shown in blue italics) to it and save it as ChangePWD.cmd

@echo off
for /f "tokens=1,2* delims=," %%h in (servers.csv) do (
pspasswd \\%%h %%i %%j>>output.txt ||echo !!ERROR!! The server name %%h  is not reachable or ID %%i is not found >>output.txt
)
cls
echo.
echo.
echo.
echo Script has completed..
Pause >nul

Step 2:- Now open excel and put ServerNames in column A, the user ID in Column B & new Passwords in Column C and save it as Servers.CSV. when opened in notepad it will look something like this. Don't put anything on the first row.

Server1,administrator,5IH881jd
Server2,administrator,IH3g1jda
Server3,administrator,asdfsa3

Step 3:-Download pspasswd.exe from http://live.sysinternals.com (direct link http://live.sysinternals.com/pspasswd.exe)

Step 4:- keep all three files ( ChangePWD.cmd, Servers.csv & pspasswd.exe) in one folder.

Now execute the ChangePWD.cmd file and it will start resetting passwords on all servers listed in servers.csv and will write the result in a new text file called output.txt.


Please post for any query/feedback/suggestions on this.

Friday, October 11, 2013

Check User Account status and Unlock it if it is found Locked

This Simple batch script can be used to check the status of a user account (Domain account also) and if it is found Locked it will unlock it.

Copy and paste the following lines of code in a batch file and save it as Check&UnlockAccount.cmd

@echo off
:A
setlocal enableextensions
set isLocked=Locked
for /f "tokens=1-3 delims= " %%a in ('net user username ^| find "Locked"') do (set myvar=%%c)
rem echo %myvar%
IF "%myvar%"=="%isLocked%" (net user
username ^/active:yes) ELSE (ECHO Account is already Active)
timeout /t 30
Goto A:



All what is needed now is double click this script and it will start doing the check and unlock:

Note: timeout /t 30 means it will check the account every 30 seconds which can be increased or decreased from -1 to 99999 (seconds) -1. (-1 means it is always timed-out and waits for you to press any key);
If this script is needed for checking a Domain Account then replace the command net user username with net user /domain username  and save it. (it is net user /domain and not the actual domainname) (obviously the id invoking this script should have permissions to unlock the user account in question.

Please post for any feedback/comment/suggestion/query

Create multiple RDP files for different servers Batch File

Creating mass/multiple RDP files just using a simple batch script.

Copy the content below in a notepad file and save it as CreateRDP.bat

@ echo off
for /f "tokens=1,2* delims=," %%h in (servers.csv) do (echo full address:s:%%i >>%%h.txt
type template.txt >> %%h.txt
ren %%h.txt %%h.rdp
echo RDP File created successfully for server %%h
)


In an excel sheet put server names in column A and IP address in B and save it as csv, (do not put any header line)
It will look like this when opened in notepad:

server1,10.10.10.10
server2,10.10.10.11


Create a notepad file and paste the content below and save it as template.txt

screen mode id:i:1
desktopwidth:i:1280
desktopheight:i:800
audiomode:i:2
authentication level:i:0
autoreconnection enabled:i:1
bitmapcachepersistenable:i:1
compression:i:1
disable cursor setting:i:0
disable full window drag:i:1
disable menu anims:i:1
disable themes:i:1
disable wallpaper:i:1
displayconnectionbar:i:1
keyboardhook:i:2
redirectclipboard:i:1
redirectcomports:i:0
redirectdrives:i:0
redirectprinters:i:0
redirectsmartcards:i:0
session bpp:i:16
prompt for credentials:i:0
promptcredentialonce:i:1
winposstr:s:0,3,0,0,800,600
allow desktop composition:i:0
allow font smoothing:i:0
redirectposdevices:i:0
drivestoredirect:s:
negotiate security layer:i:1
remoteapplicationmode:i:0
alternate shell:s:
shell working directory:s:
gatewayhostname:s:
gatewayusagemethod:i:4
gatewaycredentialssource:i:4
gatewayprofileusagemethod:i:0


keep all three files created in above steps in one folder, (createrdp.bat, servers.csv & template.txt).
double clicking the createrdp batch file will start creating RDP files for the servers mentioned in csv file.

Please post for any query/feedback/suggestion.