Forum Discussion
I can install a program remotely via PSEXec but can't do it via PowerShell
- Jan 15, 2024
Hi, Yosi.
Running commands remotely is a different kettle of fish to running them locally in an interactive session.
If you're getting no error at all then it sounds like the remote PowerShell session is establishing just fine and something is going wrong with the execution of the remote command.
I'd recommend using the -Wait parameter in Start-Process, as it's reasonably common that the initial setup stub exits early, well before the installation routine has done its job. Using -Wait tells Start-Process to wait for the stub and all child processes it launched to exit before returning control to the remote calling computer.
Example
Invoke-Command -ComputerName $pc -ScriptBlock { Start-Process -Wait -FilePath "c:\windows\temp\PhishAlertButtonSetup.exe" '/q /ComponentArgs "KnowBe4 Phish Alert Button":"LICENSEKEY=""XYZ12345""" /Log /LogFile c:\Dell\Phisher.log' }
You can leave out the -ArgumentList parameter from Invoke-Command since you're not using it in the remote command.
Cheers,
Lain
Thank you!
- mcresITJan 15, 2024Copper Contributordoesn't work, I copied it without the bracket in this topic...
- LainRobertsonJan 15, 2024Silver Contributor
Hi, Yosi.
Running commands remotely is a different kettle of fish to running them locally in an interactive session.
If you're getting no error at all then it sounds like the remote PowerShell session is establishing just fine and something is going wrong with the execution of the remote command.
I'd recommend using the -Wait parameter in Start-Process, as it's reasonably common that the initial setup stub exits early, well before the installation routine has done its job. Using -Wait tells Start-Process to wait for the stub and all child processes it launched to exit before returning control to the remote calling computer.
Example
Invoke-Command -ComputerName $pc -ScriptBlock { Start-Process -Wait -FilePath "c:\windows\temp\PhishAlertButtonSetup.exe" '/q /ComponentArgs "KnowBe4 Phish Alert Button":"LICENSEKEY=""XYZ12345""" /Log /LogFile c:\Dell\Phisher.log' }
You can leave out the -ArgumentList parameter from Invoke-Command since you're not using it in the remote command.
Cheers,
Lain
- mcresITJan 16, 2024Copper Contributor
- Jan 15, 2024
Invoke-Command -ComputerName $pc -ArgumentList $pc ? These variables shouldn't be the same?
- LainRobertsonJan 15, 2024Silver Contributor
Looking at their first command line - the PowerShell example, they're not using the supplied argument in the command to begin with, so it could be left out altogether.
But equally, it also means it can't be the reason for the failure (at least not from -ArgumentList, though it could be for -ComputerName).
Cheers,
Lain