sachingaikwad
Enthusiast
Enthusiast

After reverting snapshot, need a way to know if the VM is ready to accept commands

Jump to solution

In my script, I am reverting the snapshot with these commands.

$TARGET_VM = Get-VM $vm_name

$TARGET_SNAP = Get-Snapshot -VM $TARGET_VM -Name $snap_name

Set-VM -VM $TARGET_VM -Snapshot $TARGET_SNAP -Confirm:$false

After reverting the snapshot, I need to run bunch of commands, but the commands fails as the system is not ready yet to receive the command.

After snapshot is reverted, If I launch the web console, I see that the timestamp matches with the time when it was created (a week before). System doesn't respond to any mouse interactions, It feels like the Virtual machine is busy updating the timestamp. Due to this, even the successive commands fail.

I verified that "C:\Program Files\VMware\VMware Tools>VMwareToolboxCmd.exe timesync status" output is 'Enabled'

I also tried executing w32tm command after snapshot is reverted: "PsExec \\$vm_ip -h -d -u `"$vm_user`" -p `"$vm_pass`" -i cmd.exe /c `"w32tm /resync`"

But the system fails to execute the command as it is busy syncing the time.

As a workaround, I have introduced a hard wait. But please suggest if any such below option is available or if there is a better way to wait for the script until the system is ready to accept the commands.

  • Revert the snapshot with the host time
  • Query the status of the system if it is ready to accept remote commands
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

I often use the GuestOperationsReady property.

$vmObj = Get-VM -Name $VM

while (-not $vmObj.ExtensionData.Guest.GuestOperationsReady) {

  sleep 5

   $vmObj = Get-VM -Name $VM

}


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

View solution in original post

2 Replies
LucD
Leadership
Leadership

I often use the GuestOperationsReady property.

$vmObj = Get-VM -Name $VM

while (-not $vmObj.ExtensionData.Guest.GuestOperationsReady) {

  sleep 5

   $vmObj = Get-VM -Name $VM

}


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

View solution in original post

sachingaikwad
Enthusiast
Enthusiast

Thank you so much LucD

0 Kudos