-
Notifications
You must be signed in to change notification settings - Fork 2
/
snapshot-delete.ps1
30 lines (25 loc) · 1.12 KB
/
snapshot-delete.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<#
.SYNOPSIS
Delete snapshots over a certain amount of days
.DESCRIPTION
Script used to delete snapshots in a VMware cluster over a certain amount of days
Replace Line# 18 with your vCenter URL and username/password you are going to authenticate with
Replace Line# 21 with the cluster you are wanting to query against.
.NOTES
File Name : snapshot-delete.ps1
Author : Chris Roberts chrobert@redhat.com
Prerequisite : PowerShell V2
.LINK
Script posted at:
http://github.com/chris1984/vmware-scripts
#>
# Connect to the VMware vCenter
Connect-VIServer -Server <vcenterfqdn> -User <adminuser> -Password <adminpassword>
# Set your cluster name here
$cluster = "your_cluster_name"
# Set how far back you want to look for snapshots to delete
$days_to_look = -90
# We query the cluster and get all snapshots by the date set on line 24
Get-cluster $cluster | Get-VM | get-snapshot | Where { $_.Created -lt (Get-Date).AddDays($days_to_look)} | Select VM,Name
# We remove the snapshots forcefully (without any confirmation) DANGER!!!!!
remove-snapshot -snapshot $snapshots_to_be_deleted -confirm:$false