One of the tasks that BatchPatch can help with is executing remote commands or processes across many computers at the same time. For systems administrators this is a common need, and our goal was to make it extremely easy to perform this task in BatchPatch. This way you can avoid manually writing a script that steps through each target computer one at a time, and instead you can use BatchPatch to execute the same command across your entire network of computers, simultaneously, in just a few seconds.
In the BatchPatch actions menu we have two different methods for executing remote commands. One method (Remote Commands 1 and 2) will simply execute the command or process and then report the exit code. The second method (Remote Commands 3 and 4) will execute the command or process and attempt to retrieve any output that the command or process created. Under the hood, the actual code used to execute remote processes differs with these two methods. As such, in some cases you may notice the behavior of the two different methods is a bit different. This is expected. In some cases it’s possible that a remote command will execute successfully under one method but not the other, though in many cases a remote command can be executed using either option. Because the process execution and parsing differs under the hood for the two methods, we’ve included both the non-logged and logged-output options to help maximize compatibility with remote commands.
We generally recommend that if you need to execute a command on a set of computers but you don’t need to see the output of the command, that you use the Remote Command 1 or 2 actions. An example command for this type of use case might be something like ipconfig /flushdns
where you need to flush the DNS Resolver Cache on target computers. In that case you simply need the command to execute successfully, but the command itself doesn’t produce any output that you care to retrieve.
However, in the case where you actually need/want to see the output of a particular command, you should use the Remote Command 3 or 4 actions, which in BatchPatch are listed with “(logged output)” next to them to indicate that they will attempt to retrieve the output of any command that’s run on target machines. An example of a command you might run in this instance is ipconfig /all
where you want to see the output of the IP configuration on target computers.
Executing commands remotely when you do not need to retrieve output from the command:
- Highlight your hosts in the BatchPatch grid and select Actions > Execute remote process/command > Create/modify remote command 1
- Enter your command in the new window that appears. In this example we’ll use
ipconfig /flushdns
- Execute the command by clicking the “Execute” button. This option will actually save the command to the grid and then execute it immediately. However, if you instead choose to skip the immediate execution option and select to only save the command using the “Save” button, you can still execute it later by using Actions > Execute remote process/command > Execute remote command 1.
Executing commands remotely when you need to retrieve output from the command:
- Highlight your hosts in the BatchPatch grid and select Actions > Execute remote process/command > Create/modify remote command 3
- Enter your command in the new window that appears. In this example we’ll use
ipconfig /all
- Execute the command by clicking the “Execute” button. This option will actually save the command to the grid and then execute it immediately. However, if you instead choose to skip the immediate execution option and select to only save the command using the “Save” button, you can still execute it later by using Actions > Execute remote process/command > Execute remote command 3.
- You can see in the screenshot below that I’ve displayed the cell contents of the Remote Command Output Log by middle-clicking on the cell. We can see the output of the
ipconfig /all
command.