$smtpHost = "mail.halr9000.com" $from = "VI Monitor Bot " $subject = "VI Alarms for $( get-date -format 's' )" $to = "hal@halr9000.com" $yesterday = (Get-Date).AddDays(-1) $alarms = Get-VIEvent -MaxSamples 1000 | Where-Object { $_ -is [VimApi.AlarmStatusChangedEvent] -and $_.from -eq 'green' } Write-Verbose "Found $( $alarms.Count ) alarms." $recentAlarms = $alarms | Where-Object { $_.createdTime -ge $yesterday } Write-Verbose "Found $( $recentAlarms.Count ) recent alarms." $body = $recentAlarms | Select-Object createdTime, fullFormattedMessage | Format-Table -hideTableHeaders -autosize | Out-String -width 120 $body = "
" + $body + "
" Send-SmtpMail -From $from -SmtpHost $smtpHost -Subject $subject -To $to ` -HtmlBody:$true -Body $body