Skip to content

Instantly share code, notes, and snippets.

@alanrenouf
Created February 9, 2015 04:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanrenouf/4949574fe5977026e9fe to your computer and use it in GitHub Desktop.
Save alanrenouf/4949574fe5977026e9fe to your computer and use it in GitHub Desktop.
Receiving alerts on if a VM has over a given number of snapshots
$NumberOfSnapshotsToReport = 5
$EmailFrom = "me@mymail.com"
$EmailTo = "you@yourmail.com" # Add multiple with "mail1", "mail2", "Mail3"
$Subject = "VMs with $NumberOfSnapshotsToReport or more snapshots"
$SMTPServer = "smtp.mymailserver.com"
Connect-VIServer 172.16.88.200 -User administrator@vsphere.local -Password VMware1!
Foreach ($VM in Get-VM) {
$Snapshots = $VM | Get-Snapshot
if ($Snapshots.count -ge $NumberOfSnapshotsToReport) {
$Info = $Snapshots | Select -last 1 | Select VM, Name, Created, Description
$Body += "$VM has $($Snapshots.Count) Snapshots, the last one was created on $($Info.Created) and was named $($Info.Name).`n`n"
}
}
Send-MailMessage -SmtpServer $SMTPServer -From $EmailFrom -To $EmailTo -Subject $Subject -Body $Body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment