Comprehensive data protection for all workloads
Post Reply
jeremystw
Novice
Posts: 8
Liked: never
Joined: Nov 05, 2009 6:17 pm
Full Name: J SMith
Contact:

Email Alert for Old Snapshots

Post by jeremystw »

Hello all. As part of our replication process we thought it would be helpful to monitor the age of snapshots to make sure that we do not have any snapshots older then 2 hours. To do this I used Vmware's Powershell add on "PowerCli" along with a sheduled task. I thought I would be a nice guy and share this script as it has been extremel helpful for us.

You just need to copy the below code into a file, change the variables, name it with a .ps1 extension and then create a scheduled task that launches the script. For Powershell n00bs you will need to change your powershell execution policy or sign the script. You can find out how to do this by typing get-help set-executionpolicy in powershell.

Here are the variables you will need to change to have this work in your environment
esxservername=change to your ESXserver or VC host name
user=vc or esx host user credentials
vmname=virtual machine name
.Addhours(-2)= this can be changed to any amount of time you like you can even change this to Add Days
fromaddress@example.com= from address
toaddress@company=address you would like to receive this alert
mail.company.com= your mail server


You can also change this to cover all of your VMs at once. If you need more info on doing this just let me know. Enjoy :P

Code: Select all

#created by Jeremy Smith 3/12/2010
#This script checks snapshot for a given VM and will send an email if a snapshot is older then 2 hours
#you must have powercli which can be found at
#http://communities.vmware.com/community/vmtn/vsphere/automationtools/powercli

add-pssnapin VMware.VimAutomation.Core
connect-viserver esxservername or -user root -password password
$snapage=get-snapshot -VM vmname|where {$_.created -lt (get-date).Addhours(-2)}|select created, powerstate,vm, name
if ($snapage -eq $Null){write-output "snapgood";exit 0}
else {Write-output "A Snapshot exist that is over 2 hours old"}
$emailFrom = "fromaddress@company.com"
$emailTo = "toaddress@company"
$subject = "!!A Snapshot is over 2 hours old!!"
$body = "-------Please check the Replication job for any issues----$snapage"
$smtpServer = "mail.company.com"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)
Vitaliy S.
VP, Product Management
Posts: 27368
Liked: 2799 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: Email Alert for Old Snapshots

Post by Vitaliy S. »

Jeremy, thank you for sharing the script, I'm sure this info will be helpfull for some Veeam users.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 151 guests