snapshot removal powercli

Okay so a bit of a place holder for me, as I am sick of looking up these simple commands.

update… to take a snapshot

New-Snapshot -RunAsync -VM guest -Name snapshotname

I am in the habit of naming my snapshots with the date they were created and my username, in the description field I will put in any detailed information. So on a product release we end up with 7 and up guests with snapshots, the next day comes the cleanup process. So instead of running through every single guest we can simply run these..

First get the snapshots relative to the guests running.

Update…….
Use the below code instead of the old code “Get-VM | Get-snapshot …..” as it is quicker and easier to remember.

New Code (note that the name field is first – this allows for easy copy and paste into a snapshot removal code framework)

Get-Snapshot * | Select Name, VM, SizeGB, Created | ft -au

Old Code

Get-VM | Get-Snapshot | select @{name="VM Name"; Expression={$_.vm.name}},name,created | ft -au

Then delete based on the snaphot name as it appears from the output of the above command.


Get-Snapshot * "date of snapshot-usename" | Remove-Snapshot

To suppress confirmation


Get-Snapshot * "date of snapshot-username" | Remove-Snapshot -Confirm:$false

Of course it goes without saying that if somebody else created a snapshot today with the days date that would be removed as well. You could always append your name to the start or the end and then it would be unique.

There are plenty of examples out there…

http://www.interworks.com/blogs/dholm/2011/10/16/bulk-vmware-snapshot-managementremoval-powercli

http://blog.eeg3.net/2010/10/15/nifty-powercli-one-liners/

Advertisements