Adding and Removing Snapshots- Powercli

I never like to use the gui for a repeatable tasks when the command line is quicker and more efficient. This very quick post will show you how to add and remove snapshots to help with those CR’s in the middle of the night.

Check out my connect to multiple virtual centre post to help with connecting to all your VC’s at once.

Set the VM’s that you want to target into a variable e.g.

$vms = get-vm VCD82-02,VCD82-01,SQL01

##or by folder or what ever works for you##

$vms = get-vm -location VCD

Check that you have the right VM’s in the variable


I also like to check to see if there are any snapshots currently on the VM’s. As you can see i did, ….go to Delete Snapshots section

Get-Snapshot $vms

Create Snapshots:

Get-vm -name $vms | New-Snapshot -Name 'Something Meaningful' -Description "Created $(Get-Date)" -RunAsync

This will create a none memory snapshot, if you want to create a snapshot that is running when you revert back to it add on the below -memory and -Quiesce if you want to quiesce the file system as part of the snapshot process, more info here e.g.

Get-vm -name $vms | New-Snapshot -Name 'Something Meaningful' -Description "Created $(Get-Date)" -RunAsync -Quiesce -Memory

Once completed check the snapshots are present

get-snapshot $vms

Delete Snapshots:

Get-VM -name $vms | Get-Snapshot | Remove-Snapshot -confirm:$false