What do you do when you need to run a command on a remote computer? Using the free PDQ Inventory you can run commands on remote computers all you want. If you’ve ever used the awesome PSTools then you’ll know how important it is to run a good Windows remote command on your networked computers.
Before we begin, it’s important to understand what is happening when we use the Remote Command feature in PDQ Inventory. When you initiate a Remote Command against a target computer you are actually running that command “locally” on the actual target. The “remote” part comes from the fact that you are defining the command from your PDQ Inventory console. When you actually submit the Remote Command a Windows Service is created on the target computer and that service passes the command you defined to the local CMD.exe process. This means that any command you supply has to exist (or is accessible) on the target system. Let’s get started.
To kill a Freecell game on a remote computer you could type:
taskkill /f /im freecell.exe
Plus, with Remote Command in PDQ Inventory you don’t have to limit yourself to running a command on just one computer. If you really want to piss off the freecell players at your company you can select multiple computers or even a PDQ Inventory Collection as your target. The screenshot below shows me killing freecell.exe on all the computers in the “Accounting computers” collection.
The 11 computers in the Collection called “Accounting computers” would then be targets for the Remote Command.
How about wanting to quickly stop and start a service. You can “restart” a service by running two commands on the same command line. In the example below we will stop and start the DNS Client service. This can be handy when a target computer needs its DNS cache updated.
In the command above I simply passed to “net.exe” commands. One to stop the DNS Client service (the service name is dnscache) and one to start it. (Windows doesn’t have a native CLI, outside of PowerShell, to “restart” a service). This is a great example, however, of running two commands in sequence. We separate the different commands with a single Ampersand ‘&’. BTW, you can use two Ampersands ‘&&’ and that will run the next command only if the preceding command finished successfully.
Let’s get a little trickier. Since the awesome suite of tools ( I mentioned them earlier) known as PsTools are freely available I highly recommend that you download and use them in your everyday Sys Admin tasks. In this case, let’s use the command ‘PsService’ to actually RESTART a service. This way we wouldn’t have to use the two separate net.exe commands (shown above) to stop and then start a service.
In this example I have the PsTools suite available on a file server known as Scranton (for you The Office fans out there…you’ll get the reference). The Share name on Scranton is called “Deploy”. I just need to type in the full UNC to the PsService.exe command to run it.
\\Scranton\Deploy\Microsoft\PsTools\PsService.exe restart dnscache -accepteula
The arguments that I pass PsService.exe are 1) the service instruction (restart) and 2) the name of the service (dnscache). I also pass the
argument to prevent the End User License Agreement (EULA) window from hanging the entire process.
Note the Credentials field. The user account I am using is Quintana running in the Deadwood domain. In this case, Quintana MUST have the appropriate permissions to access and execute the PsService.exe utility on the remote server (Scranton). Quintana also must (obviously) have Administrator rights on the target computers.
One more note: Any command that you execute from Remote Command cannot have any prompts or windows that must be answered to execute correctly. An example is this:
Let’s say you want to copy an updated file called CompanyRules.avi from a network share to the target computer. You intend to use the native ‘copy’ command in Windows. If the target computer already has an older copy of CompanyRules.avi you will get a prompt asking if you want to overwrite the existing file. This prompt will cause the Remote Command to hang indefinitely since this prompt cannot be answered remotely. To get around this you would need to use the /Y argument.
In the example below you will see that I locally ran two copy commands. The first without the /Y argument. Since CompanyRules.avi already existed I was prompted to confirm that I wanted to proceed. Since I was running this locally I was able to answer ‘Y’ and proceed. This would have, however, Timed Out using a Remote Command unless I passed the /Y argument. You can see two examples of passing /Y. Once locally and once via Remote Command.
Here is how you would do this via a Remote Command in PDQ Inventory
So there you go. Definitely use the Remote Command feature. It will become essential in your everyday duties. Think of the commands that you commonly need to run and consider using them here. Now, go kill some more Freecell games.