VMware Cloud Community
VmwareScout340
Contributor
Contributor
Jump to solution

Snapshot removal Script

I am looking for a script that I can run once a month to clean up old snapshots. The problem is I have multiple clusters where the snapshots shouldn't be removed (either Exchange or Desktop parent images).

Has anyone come across anything like this and have any examples of what they used?

Thank you

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this, it will not look at the snapshots on the VMs in Cluster1 and Cluster2.

$excludeClusters = "Cluster1","Cluster2"

$now = Get-Date

Get-Cluster | where {$excludeClusters -notcontains $_.Name} |

Get-VM | Get-Snapshot | where {(New-TimeSpan -Start $_.Created -End $now).TotalDays -gt 14} |

Select VM,Name,Created


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

The basics are the Get-Snapshot and the Remove-Snapshot cmdlets.

But you have to give a bit more info on the selection criteria you want to use.

For example, can you filter out the unwanted clusters based on their name ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
VmwareScout340
Contributor
Contributor
Jump to solution

I would prefer to filter out the unwanted clusters by name.

Other criteria would be to remove snapshots older than 2 weeks.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this, it will not look at the snapshots on the VMs in Cluster1 and Cluster2.

$excludeClusters = "Cluster1","Cluster2"

$now = Get-Date

Get-Cluster | where {$excludeClusters -notcontains $_.Name} |

Get-VM | Get-Snapshot | where {(New-TimeSpan -Start $_.Created -End $now).TotalDays -gt 14} |

Select VM,Name,Created


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
VmwareScout340
Contributor
Contributor
Jump to solution

That looks perfect. All I have to do now is add | Remove-Snapshot -confirm:$false and put it on a schedule.

Thank you

0 Kudos