Stuck command in Powershell but not in Cmd.exe
-
21-12-2019 - |
Question
i'm facing a problem, my powershell script have a very strange comportement.
There is a little piece of a big script :
Write-Host "Installation in progress..."
Invoke-Command -Session $session -ThrottleLimit 64 -ScriptBlock {.\XenDesktopServerSetup.exe /QUIET /CONFIGURE_FIREWALL /components $using:componentparam /nosql }
Write-Host "Installation completed"
Sometimes even if the execution of XenDesktopServerSetup.exe
is finished my script doesn't pass to the next command Write-Host "Installation completed"
I need to click somewhere in the shell or break the script with CTRL+C to see the end of my script;
I tried to change ThrottleLimit
, but i doesn't have effect.
I'm using Powershell V4.0.
There is only one server in $Session.
EDIT : I tried this command directly on my server, i opened a PS Shell and executed :
.\XenDesktopServerSetup.exe /QUIET /CONFIGURE_FIREWALL /components CONTROLLER /nosql
I had the same problem !
But when i tried the same command in Cmd.exe, it works perfectly and everytime !
How can i execute this command in Cmd.exe ? I want something like this :
Write-Host "Installation in progress..."
Invoke-Command -Session $session -ThrottleLimit 64 -ScriptBlock {Cmd.exe .\XenDesktopServerSetup.exe /QUIET /CONFIGURE_FIREWALL /components $using:componentparam /nosql }
Write-Host "Installation completed"
This shows us that there is a difference between cmd.exe and powershell in how PS make the call of .exe file, but I don't understand at all why it works in cmd.exe but not in powershell
Thanks for your suggestions
Solution 2
This is how i resolved it, I tested it a lot and i don't have any issue :
Write-Host "Installation in progress..."
Invoke-Command -Session $session -ScriptBlock {$Components = $using:componentparam}
Invoke-Command -Session $session -ScriptBlock {Invoke-Expression "cmd /C '$IsoLetter\x64\XenDesktop Setup\XenDesktopServerSetup.exe' /QUIET /CONFIGURE_FIREWALL /components $Components /nosql" }
Write-Host "Installation completed"
What do you think? I think the problem is in the .exe file.. there is something wrong with.
But finally i solved it by using Invoke-expression
and cmd /C
OTHER TIPS
Are you sure all of the remote servers are done? You could use the -AsJob parameter and then periodically inspect the state of each job using Get-Job. Retrieve output with Receive-Job. You can even wait for all to finish with a timeout using Wait-Job $jobs -Timeout 120