Share via

Invoke-command doesn't stop stop for installers that do not have support for silently running

MyHi 21 Reputation points
2021-01-12T16:05:42.07+00:00

$s= New-PSSession -VMName $my_vm -Credential $creds
try
{
Invoke-Command -Session $s-Block {
$psi = New-Object System.Diagnostics.ProcessStartInfo
$psi.FileName = $using:installer
$psi.Arguments = $using:args
$psi.UseShellExecute = $false
$psi.RedirectStandardOutput = $true
$proc = [System.Diagnostics.Process]::Start($psi)
$proc.StandardOutput.ReadToEnd()
$proc.ExitCode
}
}
catch [Exception]
{
echo "Error while running the remote command", $.Exception.GetType().FullName, $.Exception.Message
Remove-PSSession $s
exit 1
}
Exit-PSSession

I have this code that works perfectly for the case when the installers have support for silent running, but when I try to run an installer that cannot be run silently, it cycles and does not stop. The processes on the remotely machine are open, and it's like waiting for some input, I don't know exactly what it has. Any hints ?

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

2 answers

Sort by: Most helpful
  1. Bill Stewart 186 Reputation points
    2021-01-12T21:43:53.227+00:00

    Exactly. If the executable is expecting interactive input and it's not getting any, it will simply run indefinitely and will not complete. (Because it got no input, you see.) If that executable provides no means to run it without prompting for input, then you cannot automate it, obviously, because there's nobody there to enter the input interactively.

    Was this answer helpful?


  2. Bill Stewart 186 Reputation points
    2021-01-12T18:11:53.8+00:00

    If the executable is stopping for input, and there's nobody in that session to provide that input, then of course the executable will run indefinitely. (I'm not sure what exactly you would expect to happen?)

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.