rolfbar
Contributor
Contributor

Restart-GuestVM not exiting

Hello Everyone,

I have a situation where we are calling a PS1 (PostDeployScript) scripts from within another PS1 script (VMPoll), and in the PostDeployScript we have the cmd

....

"Log to syslog server - Rebooting "

$vm | Restart-GuestVM -Confrim:$Fasle

"Log to syslog server - Rebooted "

....

Now this use to work fine with PowerCLI 6.5 and PowerShell v4, Ever since we upgraded to PowerCLI 11.0.x and PowerShell v5 the PostdeployScript get's held up at the Restart-GuestVM and never continues further, the powershell thread is still running and the Postdeploy never completes, almost as if it's waiting from some feedback or response. The VM does actually reboot as this can be seen the VC tasks.

If we change the line

$vm | Restart-VM -Confirm:$Fasle -RunAsync

Then the script continues as expected, but this now means the first login post the reboot we see the error "unexpected reboot"

Any help wold be appreciated

0 Kudos
3 Replies
LucD
Leadership
Leadership

Works fine for me with PowerCLI 11.0.0 and PSv5.1.

What does this show (place it before the Restart-VMGuest line)?

$vm.ExtensionData.Guest

Are you on PSv5 or PSV5.1?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
rolfbar
Contributor
Contributor

Hey Luc,

PowerShell 5.1.14409.1005

VMware PowerCLI 11.0.0 build 10380590

Just to give more details

We call this fomr the VMPoll.PS1

$postdeployment = 'CP-PostDeployment.ps1'

$sb = [scriptblock]::create("$postdeployment $VmId $SCCMSite")

start-job -ScriptBlock $sb

In CP-PostDeployment.ps1

LogEvent ("CP-PostDeployment: Rebooting $Hostname VmID $VmID")

$vm | Restart-GuestVM -Confirm:$False

LogEvent ("CP-PostDeployment: Setting Status $Hostname VmID $VmID to 11")

with the above the first log event is sent and the restart works the VM is rebooted but the 2nd send LogEvent is not captured and there are some email cmd's after that which never happen, the VMPoll.PS1 will wait till the CP-PostDeployment.ps1 completes and exits. In this case the PostDeployment.ps1 runs indefinitely

If I run

$vm | Restart-VM -Confirm:$False -RunAsync    instead of the Restart-GuestVM everything resumes as normal, Now I know I am adding -RunAsync which is fire and forget.

If I open PowerCLI and manually run the CMD's it all works as expected, the VM's reboot and the system returns to the prompt.

as we are running these via an automated process we don't see the output of any of the cmd's so adding $vm.ExtensionData.Guest so anywhere.

I will see if we can't capture that in the LogEvent and see what it writes.

Thanks for the help

0 Kudos
LucD
Leadership
Leadership

I just wanted to check that the VMware Tools were running and accepting guest operations, at the moment you launch the Restart-VMGuest cmdlet.

I have noticed before, on freshly deployed VM, that it might take some time before the VMware Tools actually start accepting commands.

You can see that in $vm.ExtensionData.Guest.GuestOperationsReady , it should say $true.

I used a loop to wait for that flag to say $true (and added a timeout to avoid an eternal loop in case of VMware Tools issues)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos