Creating a Snapshot:
Creating a snapshot can be done using the New-Snapshot cmdlet which supports flags for capturing the memory contents, and also quiescing disk activity during this process.
New-Snapshot -VM win2012R2 -Memory -Quiesce -Name “Test Snapshot” -Description “Created by: mikelaverick@corp.com Date: 09-Apr-2014 Reason: Before Windows Update”
Reverting a Snapshot:
$snapshot = Get-Snapshot -VM win2012R2 -Name “Test Snapshot” Remove-Snapshot -Snapshot $snapshot -RemoveChildren -Confirm:$false
Deleting a Snapshot:
The Remove-Snapshot cmdlet take the snapshot and deletes it, the -RemoveChildren flag takes all the snapshots and consolidates them into a single virtual disk file.
$snapshot = Get-Snapshot -VM win2012R2 -Name “Test Snapshot” Remove-Snapshot -Snapshot $snapshot -RemoveChildren -Confirm:$false
Locating VMs with Snapshots:
Typically, vCenter Admins snapshot a VM(s) and then forget that they have. So the worry is that lots of VMs can build up with uncommitted snapshots cause an outage by them running out of disk space or cause poor performance when engaged for long periods of time. This script search the entire vCenter Inventory return all VMs that have a snapshot, and use the Select command to report on various attributes including the date they were created and how big the snapshots are – finally it sorts the report by the Created date – showing the oldest snapshots at the top of the list. This is just one example/sample – there are many more sophisticated scripts that report on the snapshot status.
Get-VM | Get-Snapshot | Select Created, VM, Description, SizeMB | Sort Created
Bulk Snapshot VMs by Wildcard:
You can snapshot a group of VMs by either having a very good naming convention, and using wildcards to identify the VMs, or using other filters such as every VM in a particular VM folder for instance.
New-Snapshot -VM CorpHQ* -Memory -Quiesce -Name “Test Snapshot” -Description “Created by: mikelaverick@corp.com Date: 09-Apr-2014 Reason: Before Windows Update”
Bulk Delete the VM Snapshot:
Foreach ($vm in get-vm CorpHQ*) { $snaps = get-snapshot -vm $vm remove-snapshot -snapshot $snaps -RemoveChildren -confirm:$false }