Last week I was asked if there was an easy way to get an alert once a VM had over a certain number of snapshots, this is a frequent request as it would seam some backup products like to keep snapshoting VMs and note removing them.
There are several ways this could be kicked off, including setting a vCenter Alarm on snapshots and getting it to run a script but in this case it was simple, they wanted to run a scheduled task once a day and get an email listing the VMs that had over x amount of snapshots and the details about the last one created, of course it was a 5 minute script but I thought I would blog it anyway for others to use if they needed it. Enjoy
BTW, its also very easy to get this to work with gmail if you use that as your email provider, just replace the Send-EmailMessage line with the below:
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“my.email@gmail.com”, “mYpa$$w0rd”);
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
Is there any way to create an vCenter alarm for Snapshots older then X days?
Never mind, figured it out myself, thanks!
Hi,
Tried to use the script and I’m getting an error:
“Send-MailMessage : Cannot validate argument on parameter ‘Body’. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.”
Any idea what could be wrong?
Thanks
Sure it can, just add this to the end of line 13:
| Where { $_.Created -lt (Get-Date).AddDays(-14)}
Can this script be extended to show snapshots that are older than a certain number of days?
For example it will only show snapshots that are older that 14 days old and include the total.
Pingback: [VMware] news + interesting reads from the blogosphere: 09 Feb 2015