Revert to snapshot from within a VM

Posted on January 27, 2011 • 1 min read • 137 words
For a couple of ThinApp packaging machines I didn’t want that the packagers had access to the vCenter Client, but still let them revert to a…

For a couple of ThinApp packaging machines I didn’t want that the packagers had access to the vCenter Client, but still let them revert to a previous snapshot.

So I wrote a couple of lines to accomplish just that from within the packaging machine itself.

The script below reverts the virtual machine back to the snapshot that was created earlier.

get-viserver 
$vmname=$env:computername 
$snapname="PoSH snapshot" 
$snap=Get-Snapshot -vm (get-vm -name $vmname) -name $snapname 
set-vm -vm (get-vm -name $vmname) -Snapshot $snap -confirm:$false

Prequisites for this are that PowerShell is installed on the machine as is the PowerCLI. You also need a user account that has just enough permissions in vCenter to connect, do some VM actions like reboot and revert to snapshot.

See also

    Follow me