With the above, everything works remotely (such as killing the “Alloc” processes remotely on Computer2) BUT - except for the very last line - which is to start the “.bat” file where I get the following error: "A Parameter cannot be found that matches parameter name ‘ComputerName’ (This tells me that Start-Process does not work remotely so I went with an Invoke-Command to see if that works better So I replaced the very last line with an Invoke-Command instead:
Invoke-Command -ComputerName “Computer2” -ScriptBlock {Invoke-Expression -Command:“cmd.exe /c ‘C:\ProgramData\Merrick\Allocations.bat’”}
Then I get the error that “Input Redirection is not supported.” and I see the batch file trying to execute but with each break, it just fails.
Below is the content of the actual batch file I have to run remotely on Computer2 from Computer1 within the powershell file above:
so the problem is not with the powerhsell file, or the batch file, the problem is trying to figure out how to run a PS file on Computer1 which contains a batch file to run remotely on Computer2 with all these timeout redirections.
Note: I can run a simple PS script (Start-Process C:\ProgramData\Merrick\Allocations.bat) locally on the actual server Computer 2 - and CMD starts up and everything is gravy! But I need to be able to run this remotely from a tool like OpenBatch or a staging server’s task scheduler…etc.
Please advise, thanks
You are using Powershell, command line tools, and a DOS batch file…yikes. I would say that you could make your life much easier using a full Powershell solution versus messing with a batch file. My .02
Hi Rob, can you please elaborate on using a full Powershell solution versus messing with a batch file? Do you mean, writing the vendors batch file as a PS script instead or *.bat?
Where you can have the script(c:\YourNewScript.ps1) in the local machine itself and PowerShell will take care of executing the script in remote machine.
Well, first we’d have to see what is the batch file. My assumption is the batch is just starting an exe with some params,so you can just skip the batch and do that directly with Start-Process. But even what it posted is doing a Get-Process and the using taskkill.exe to stop the process versus Stop-Process. It can be as simple as: