Remove all snapshots older than 6 weeks with one line of PowerShell

My last post got me thinking… I myself have a rule-of-thumb that all snapshots will be removed in my environment if they are older than 6 weeks.
I used to do this manually with the SCVMM console… but I dislike manual labor Bedroefde emoticon

So, I did some playing around in my latest favorite tool: PrimalScript Glimlach
This is what I came up with:

Get-VMCheckpoint | ForEach-Object {if ($_.AddedTime -lt (Get-Date).AddDays(-42)) {Remove-VMCheckpoint -VMCheckpoint $_}}

As you can see, I am using the AddDays method. Why I did not use the AddWeeks method?
Simple answer: It doesn’t exsist (yet) Knipogende emoticon


  1. Atouba5 says:

    Hi Jeff, is it also possible to “remove old snapshots” without the scvmm?

  2. Jeff Wouters says:

    Hi Atouba5,
    Sure that’s possible. When using Windows 8 you can use the native Hyper-V PowerShell cmdlets, but if you’re running an earlier version you can either download the Hyper-V PowerShell module from CodePlex, created by James O’Neill. And if neither of those is an option for you, using WMI and the native buildin PowerShell modules Windows 7 / Server 2008 R2 can do the trick. Read the following post by Ben Armstrong for more information on the later:

Leave a Reply

Your email address will not be published. Required fields are marked *