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
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)