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
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
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
I would prefer to filter out the unwanted clusters by name.
Other criteria would be to remove snapshots older than 2 weeks.
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
That looks perfect. All I have to do now is add | Remove-Snapshot -confirm:$false and put it on a schedule.
Thank you