Sunday, March 25, 2012

Remove all snapshots for virtual machines in a folder with VMware vSphere PowerCLI

I find that the best way to streamline the process of removing snapshots for a bunch of virtual machine master templates I use for several linked-clone pools is to use PowerShell CLI.  This enables me to avoid having to repetitively go through the VMware View Administrator console to delete snapshots one after another for multiple templates and because I don’t live and breath through PowerCLI on a regular basis, I’ve decided to blog the cmdlet so I have something to reference to in the future when I haven’t done any deployments or administrative tasks.

Let’s say you have a folder named Master Images with all of the virtual machines and they have one or more snapshots:


Rather than using the Snapshot Manager from vCenter, you can execute the following command via the PowerCLI console:

Connect-VIServer <vCenter Name or IP>


Get-VM -Location "Master Images" | Get-Snapshot | Remove-Snapshot -Confirm:$false




Now when you check the snapshots for virtual machines in that folder, the snapshots should be removed:


Alternatively, if you simply want to remove snapshots for only 1 virtual machine, you can use the following cmdlet:

Get-VM -Name <VM Name> | Get-Snapshot | Remove-Snapshot -Confirm:$false

1 comment:

Unknown said...

Thank you for this post, very helpful.