I just wanted to take a moment to thank both of you @mklement0 and @Bitcoin Murderous Maniac for your incredible help. After much effort and troubleshooting, I have finally managed to solve the issue with your help 🎉 Here is my solution I'd like to use until further notice:
$InstallerPath = "C:\tmp\PathToExe.exe"
$argList=@('-q','-c','-dir','C:\Installer\target\directory')
$ScriptBlock = {
param(
Parameter()][string]$PathToExe,
Parameter()][System.Object[]]$ArgumentList
)
# Just for debugging
"PathToExe: $PathToExe, args: $ArgumentList"
& $PathToExe $ArgumentList | Write-Output;
$LASTEXITCODE
}
Invoke-Command -Session $SessionHost `
-ScriptBlock $ScriptBlock `
-ArgumentList $InstallerPath,$argList `
-AsJob
With this solution, I hope, this is a quite future proof solution and I shouldn't get any troubles for the next installers/EXE files.
Thanks again for your support!