Using PsExec to Run Commands on a Remote Workstation

PsExec is a handy tool used to execute commands on a remote system.  It is part of SysInternals from Technet download or can be downloaded and installed separately from the PsExec description page.

I have used this tool in the past to kick off the Windows Update command,

wuauclt.exe /detectnow

in order to have the remote workstation contact my Windows Server Update Server (WSUS) to look for updates and report status. If I have a list of computers to contact, I can simply enter the list into the the command line and one by one it will logon to each workstation and run the command. You will be prompted for a Username and Password when the command is run.

I have created a Batch File that will automatically prompt for a computer list and Username and Password to enter into the command:

ECHO OFF

:s_routine_1
CLS
ECHO *******************************************************************************
ECHO * *
ECHO * Execute the command for Windows Update on a Remote PC *
ECHO * *
ECHO *******************************************************************************

ECHO Enter Computer Names separating each with a comma (Ex. C0962,C0963).
Set /P _CompName=

ECHO.

ECHO Enter Username (Ex. Domain\Username):
SET /P _UserName=

psexec \\%_CompName% -u %_UserName% wuauclt.exe /detectnow

CHOICE /M "Would you like to perform this action on another computer?"

goto s_routine_%ERRORLEVEL%

:s_routine_2
exit

This is just one example of how this command can be used. The possibilities are endless and knowing this tool is a must for any Windows System Administrator.

Advertisements
This entry was posted in Windows Commands, Windows Server and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s