I'm looking for some help with a setup I have where I copy batch files from my local PC to a remote office computer using Remote Desktop Connection. After I transfer the files, I usually double-click them to run. Now, I want to automate this process by creating a script that not only copies these files but also executes them directly on the remote computer when I right-click.
I've got a batch script that uses robocopy to move the files to the remote machine, and then it runs a PowerShell script. Here's the batch file I'm using:
```
set destination="W:UsersMy NameDesktopName AERMOD-1"
for %%F in (%*) do (
robocopy "%%~dpF." %destination% "%%~nxF"
)
powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".model1.ps1"
```
And here's the PowerShell script:
```
$cred = Import-Clixml C:PSFoldermycredentials.xml
$computerName = "192.168.0.10"
$files = "C:UsersMy NameDesktopName AERMOD-1*.bat"
$parameters = @{
ComputerName = $computerName
Credential = $cred
ScriptBlock = { cmd.exe /c $files }
}
Invoke-Command $parameters
```
Everything seems to be set up correctly, but the batch files don't execute on the remote computer, and I don't see any errors either. Can anyone help me troubleshoot this issue?
5 Answers
Have you thought about using tools like SemaphoreUI? They can help manage and run multiple PowerShell scripts efficiently on remote computers.
It looks like your `Invoke-Command` might just need a tweak. Try adjusting the final line in your PowerShell script to use the variable correctly: `Invoke-Command @parameters`. This should fix the issue and allow the scripts to run on the remote machine.
Have you tried using the remote computer’s hostname instead of the IP address for the `ComputerName` parameter? Sometimes it helps with connectivity issues.
Just a heads-up, commands executed with `Invoke-Command` might not operate in the same way as on your local machine since they don't interact with your user's session directly. That could be an issue here.
Your script block may not be recognizing `$files`. Try using `$Using:files` instead to ensure it references the variable correctly inside the script block. Also, consider looping through each file individually rather than sending them all at once, just to be safe.
I added `$using:files` but still got the same error. I must be missing something else...

I ran into an error using `@parameters`. It was a parameter set problem. I switched to `$parameters`, but I got a binding exception with `Invoke-Command`. Its saying the named parameters can't be resolved. Any advice?