Note: This article was originally written on reich-consulting.net. Reich Web Consulting has narrowed its focus to the web and no longer offers tech support services, so we?ve moved all of our tech support content off-site. We hope you find this article useful. It is provided as-is, and we will no longer provide support on this topic.
There are many instances in managing a network when it becomes neccessary, or at least more convenient, to be able to execute commands on a remote computer without the overhead of launching a full-fledged Remote Desktop session.
Until PowerShell Remoting came along there wasn?t a native way to run remote commands from Windows, and even now PS Remoting isn?t exactly intuitive. That?s where PSEXEC comes in.
PSEXEC is a utility from a developer named Mark Russinovich and his company SysInternals (long since purchased by Microsoft) that allows you to execute commands on a remote system. All you need is File and Print Sharing enabled on the remote system, and of course the appropriate user permissions to execute the command.
Here?s a quick example. Let?s say I just want to open a command line to another computer:
psexec \workstation1 cmd
This will give me a command shell (or DOS prompt if you prefer) to the computer workrstation1. But that?s pretty simplistic. Let?s try a more complicated example.
I?ve written a batch file to deploy some software, and it looks a little something like this:
@REM InstallPanda.bat – Installs Panda Cloud Security [email protected] OFFECHO Installing Panda Cloud Security Client…msiexec \fileserverPandawaagent.msi /qnECHO Installation completed with error code %ERRORLEVEL%
To run my batch file on a remote computer using PSEXEC, I could use the following command:
psexec \workstation1 -c InstallPanda.bat
The first argument \workstation1, is the name of the computer on which the command should be executed. The second argument -c, specifies that the file should be copied to the remote computer and executed from there. Of course the final argument InstallPanda.bat is the command I want to execute.
But wait, there?s more! If I wanted to execute the command on multiple computers at once, I can add the names of those computers to a text file and call:
psexec @computerlist.txt -c InstallPanda.bat
I?ve been using this psexec commands just like this as a poor man?s software deployment too for years. To download PSEXEC and for a full run-down of PSEXEC?s parameters and features, visit the PSEXEC homepage on Microsoft.com.