r/PowerShell • u/aq-modeler • Feb 09 '26
Executing batch scripts on remote computer
I normally copy and paste batch files from my local computer to a remote computer in my office using Remote Desktop Connection and then double-click those batch files on the remote computer to run them. I want to add a script to copy and then execute these files and add it to the right-click menu (which I know how to do).
I have a batch script that uses robocopy to copy the batch files that are drug onto the batch file in Windows Explorer to the remote computer. This works great. I then have that batch file execute a PowerShell script, see below:
set destination="W:\Users\My Name\Desktop\Name AERMOD-1"
for %%F in (%*) do (
robocopy "%%~dpF." %destination% "%%~nxF"
)
powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\model1.ps1"Here is the PowerShell script:
$cred = Import-Clixml C:\PSFolder\mycredentials.xml
$computerName = "192.168.0.10"
$files = "C:\Users\My Name\Desktop\Name AERMOD-1\*.bat"
$parameters = @{
ComputerName = $computerName
Credential = $cred
ScriptBlock = { cmd.exe /c $files }
}
Invoke-Command u/parametersIt does not show any error messages, but the batch files don't appear to run. If they did run, command windows should open up on the remote computer. Also, the normal output files are not being created by those batch files.
I have also run this interactively with the same result. Can anyone help me please? I just want those batch files on the remote machine to be executed, nothing needs to happen on the local computer.
View all comments
Show parent comment
1
u/aq-modeler Feb 10 '26
Thank you for your detailed response. I haven't had time to try any of your suggestions out yet but wanted to clarify what I really what my end result to be. I run a program on my local computer that generates inputs files for a model. It then generates batch files to run the model with the input files. There are usually 96 batch files created. I then copy the batch files to 3 remote computers, 32 batch files each. When I paste them into a folder on the remote computer I then hit Enter to execute them. 32 command windows pop up to run the model and close once they are done. What I'm really after is a way to simulate me hitting Enter on the remote machine to start all 32 batch files at once. I really need the 32 command windows to pop up on the remote machines. I got close to this by creating a generic batch script on the remote computer that executes all batch files in a given directory. I then tried to set up a Task Scheduler task to launch that batch script once files were copied into the folder, but couldn't get that to work.
I'd really like to use a PowerShell or batch script on my local computer that will execute those batch files on the remote machine that is just like me double-clicking on them, but I'm not sure that is possible.