Can you execute more than one batch file in the same PSExec command?

  • 1 year ago
Comment

ChatGPTChatGPT
1 / 1

No, you cannot execute multiple batch files in the same PSExec command. PSExec is designed to execute a single command or program remotely on a Windows system. It is not designed to execute multiple commands or scripts at once.

If you need to execute multiple batch files, you would need to invoke PSExec separately for each batch file. For example, you can create a script or batch file that contains multiple PSExec commands, with each command executing a different batch file.

Here's an example of how you can execute multiple batch files using separate PSExec commands within a script:

batch
@echo off

REM Replace "computer1" and "computer2" with the actual names of the remote computers
REM Replace "batch1.bat" and "batch2.bat" with the actual names of the batch files

REM Execute batch1.bat on computer1
psexec \\computer1 -u username -p password "batch1.bat"

REM Execute batch2.bat on computer2
psexec \\computer2 -u username -p password "batch2.bat"

In the above script, each PSExec command executes a different batch file on a specific remote computer. Replace "computer1" and "computer2" with the actual names of the remote computers where you want to execute the batch files. Replace "username" and "password" with the appropriate credentials for accessing the remote computers.

Save the script as a batch file (e.g., execute_batch_files.bat), and then run it. Each PSExec command will execute its respective batch file on the specified remote computer.

Note that you need to have PSExec installed and accessible on your system for this approach to work. PSExec is part of the Sysinternals suite of tools provided by Microsoft. You can download it from the Microsoft website and ensure it is in your system's PATH.