Work day: PsTools

Having an elevated PowerShell prompt makes running tasks on remote computers easier, but it’s not the only tool I use. A bunch of my small scripts rely on PsTools to perform command-line actions. In this post I’ll describe how to obtain and install the PsTools suite, and provide an example of how they can be invoked in a PowerShell script.


First, download PsTools. The link above will take you to the PsTools page on the Windows Sysinternals website; the current version of the PsTools package can be downloaded there. Clicking the link “Download PsTools Suite” will download the file PSTools.zip.

Extract the .zip file. You can keep the extracted files anywhere, but I like to keep them in a subfolder below where I store my scripts for easy reference. That’s it for installation!

To include a call to one of these tools in a PowerShell script, use something like the following. These examples assume that you have extracted PsTools to a folder called PSTools, stored under the folder where you keep your scripts.

.\PSTools\psexec \\computername "c:\program files (x86)\path\to\executable.exe" /switches /and /arguments

or

.\PSTools\psexec "\\computername -s command.cmd arguments -switches"

I’ve found that the first style works when switches are expected to be prefixed with a slash, and the second when a dash is used. Note the -s in the second command; this means that the command is being started on the remote computer in the SYSTEM context.

PSExec is the tool I use most frequently, but there’s a lot to get into in this little toolkit! I’ll share my favourite example in my next “Work day” post.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.