1

If I run the below script on the computer it works as expected and installs.

Start-Process "C:\Test_Software\TestConfigApp" " -s"

But I need to run this remotely. So this is the code I have but it is not working. $Computer is defined and is the correct device. What am I doing wrong? I have other Scripts that I run remotely to this device so I know I am getting to it correctly and not getting blocked.

Invoke-Command -ComputerName $Computer -ScriptBlock {Start-Process "C:\Test_Software\TestConfigApp" " -s"}
mr_evans2u
  • 139
  • 1
  • 5
  • 15
  • To recap: The answer below explains why your approach _fundamentally_ cannot work, irrespective of the specific executable being invoked, and, as such, your question is answered _as asked_. If you add `-Wait` to the `Start-Process` call, as recommended in the answer, and it still doesn't work, the problem must lie _with your specific executable_ - absent any information about this specific executable, your problem cannot be solved. I recommend asking a separate question about your specific executable. – mklement0 Aug 26 '21 at 02:20

1 Answers1

2

Start-Process launches a process asynchronously by default. That is, control is instantly returned to PowerShell, even if the launched process is still running.

  • In a local invocation, the launched process lives on independently of the calling process.

  • In a remote invocation, the remote session ending automatically terminates processes launched via Start-Process.

This asymmetry exists for technical reasons and is explained in GitHub issue #16001.


This means that your C:\Test_Software\TestConfigApp process most likely never gets a chance to run to completion, given that your remote session ends right after the Start-Process call.

To ensure that it does, add -Wait to the Start-Process call:

Invoke-Command -ComputerName $Computer -ScriptBlock {
  Start-Process -Wait 'C:\Test_Software\TestConfigApp' '-s'
}

Note:

  • Remoting commands run in an invisible window station, in which some GUI applications may refuse to run. When that happens, you'll need to look for a logging mechanism that can help you troubleshoot; perhaps the remote machine's event log provides clues.

  • If, by contrast, C:\Test_Software\TestConfigApp happens to be a console application, you can achieve the same effect - synchronous execution - with direct invocation (which is generally the right way to invoke console applications - see this answer):

Invoke-Command -ComputerName $Computer -ScriptBlock {
  # Only if the application is a *console* application.
  C:\Test_Software\TestConfigApp -s
}
mklement0
  • 382,024
  • 64
  • 607
  • 775
  • Invoke-Command -ComputerName $Computer -ScriptBlock { Start-Process -Wait 'C:\Test_Software\TestConfigApp' '-s' } Didn't work. I had already tried the "-Wait" and there is absolutely no activity on the remote computer – mr_evans2u Aug 20 '21 at 23:21
  • @mr_evans2u: This answer explains why your code _as posted in your question_ won't work, for which there is a good _general_ explanation. If `-Wait` doesn't help, and no error is returned, the implication is that _your specific application_, `C:\Test_Software\TestConfigApp`, is failing silently (or with a GUI notification you won't be able to see, but that would _block_ the `Invoke-Command` call indefinitely). – mklement0 Aug 20 '21 at 23:33
  • @mr_evans2u: Remoting commands run in an invisible window station, in which some GUI applications may refuse to run. You'll need to look for a logging mechanism that can help you troubleshoot; perhaps the remote machine's event log provides clues. – mklement0 Aug 20 '21 at 23:33