tl;dr
If I locally start Invoke-Command to start an EXE file remotely, it fails, if there is no active user session on the remote system.
I am facing the challenge of installing an application with an EXE file on 20+ virtual machines (Windows Server VMs) and would like to automate this process using PowerShell. Here are the steps I have implented so far:
- Copying the Installer File: this works, the EXE installer is copied to the "C:\tmp" folder on the remote system
- Copying Configuration Files: same as the installer file
- Executing the EXE File: The EXE file should be executed with specific parameters on each remote system.
In the very last step (executing the EXE file), I am desperately looking for a solution. Here are my observations:
- I start the EXE file with, e.g. this command:
Invoke-Command -Session $SessionToRemoteComputer `
-ScriptBlock {
Start-Process -FilePath "C:\tmp\PathToExe.exe" -ArgumentList "-q -c -dir 'C:\Installer\target\directory'" -Verb RunAs -Wait
} -AsJob
(Parameters "q" and "c" indicate the installer to start in "quiet" and "console" mode, hence no GUI window is involved in this process)
The command executes whitout any errors. But the EXE file is not started. However, if I connect to the remote computer with RDP and re-run the Invoke-Command on my system, the EXE file starts and installs the application successfully on the remote computer. I can reproduce it on every VM, but I have no clue why! And it is very useless, to first start a RDP connection to execute the installer remotely. I thought, to fully automate this process.
The user I'm using to start the Invoke-Command is a admin user and it is the same user, I use to login via RDP to the Remote Machines.
I'm feeling, I did every combination of Invoke-Command and Start-Process with all combinations of the respecitive parameters and I feel, I'm loosing my mind on this :-(.
Can anyone help me please!