Ready to Start Your Career?

Administrating Your Network Domain with PsTools

Matthew Williams's profile image

By: Matthew Williams

August 6, 2015

Administrating Your Network Domain with PsTools - CybraryUsing PsTools:With PsTools, there are a number of different utilities included. The two I'll focus on are: PsExec and PsShutdown. The rest are useful, too, and you can apply these techniques and batch files to them fairly easily.
  • PsExec is used to execute remove cmd commands or processes on domain connected servers or workstations. I actually find myself using PsExec to register DLL files on my domain computers, run update files, MSI installation remotely, etc.
  • PsShutdown is used to remotely restart or shutdown a workstation or server on the domain. I utilize this feature on my domain to force users to restart their machines if they leave them on after work or apply updates. You can also force logoffs for users that stay locked onto a machine and you have GPO’s that prevent the switch user button from being used when someone is logged in (prevents multiple users logging into the machine and reducing machine performance).
 Get Started: Syntax:All PsTools have similar syntax associated with them. I’ll start with PsExec and then cover PsShutdown.In order to specify the machine you want to use, you'll need to tell PsExec the IP address or the domain name for the machine or server:

psexec \(NAME or IP) (COMMAND)

For example:

psexec \192.0.1.2 regsvr32 "C:Program Files (x86)123456.dll"

 As you can see, I'm executing the regsvr32 command on the machine 192.0.1.2. Then, I'm entering the specifications or modifiers that regsvr32 requires.Next, remember to use a password and username when the program or command executes. The string above will likely give you an error saying you don’t have permission or it will close without doing anything. We use a modifier of –u for username and –p for password and we'll get the following script:

psexec \192.0.1.2 -u happydomainadministrator -p 123456 regsvr32 "C:Program Files (x86)123456.dll"

This will use the username "administrator" with the password "123456" to execute the command regsvr32 and register the 123456.dll on the machine 192.0.1.2In PsShutdown, type:

PsShutdown \192.0.1.2 -u happydomainadministrator -p 123456

This will shutdown the machine with the default of 20 seconds before shutdown.PLEASE NOTE: This will not restart the machine. To do that, you'll need to use the –r modifier at the end.You can also use the –f modifier to force the restart and do so like:

PsShutdown \192.0.1.2 -u happydomainadministrator -p 123456 -f -r

You can read more about possible commands and additional arguments on the Microsoft website listed above. Creating a Batch File Script:Let’s assume you know how to create batch files and you know how to save and edit them. From this, we can create the following example script.Example Script:
*************************************************************************************@ECHO OFFcd (PATH TO PSTOOLS)SET /P comp=Please enter the Computer!IF "%comp%"== "" GOTO errorPsExec \%comp% -u (DOMAINUSERNAME) -p (PASSWORD) systeminfoPAUSEEXIT:errorECHO You did not select a machine!PAUSEEXIT*************************************************************************************
You can replace the sections in parentheses above to customize your script and use it to administer machines on your domain remotely. Thanks and I hope this information is useful to you.
Schedule Demo