# encoding: ascii
# api: powershell
# title: restore-LastSnapshot
# description: Revert to the last VMware snapshot with variables for Vvcenter and VM
# version: 0.1
# author: TXGUY
# license: CC0
# x-poshcode-id: 6159
# x-archived: 2016-03-19T02:55:14
# x-published: 2016-12-31T19:13:00
#
# usage: restore-LastSnapshot -vcenter vcenter1 -vm vm1234
# Assumes powercli module has been loaded.
# You can ommit the -vcenter [vcenter] if you have already manually ran connect-viserver
#
#
#restore-LastSnapshot
#Reverts specified VM to last (most current) snapshot
#
#
param(
[string]$vcenter,
[string]$vm
)
connect-viserver -server $vcenter
$snap = Get-Snapshot -VM $vm | Sort-Object -Property Created -Descending | Select -First 1
Set-VM -VM $vm -SnapShot $snap -Confirm:$false
start-vm -vm $vm