Created
February 9, 2015 04:07
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$NumberOfSnapshotsToReport = 5 | |
$EmailFrom = "[email protected]" | |
$EmailTo = "[email protected]" # Add multiple with "mail1", "mail2", "Mail3" | |
$Subject = "VMs with $NumberOfSnapshotsToReport or more snapshots" | |
$SMTPServer = "smtp.mymailserver.com" | |
Connect-VIServer 172.16.88.200 -User [email protected] -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