List vCenter Alerts that Trigger an Email
Need a CSV list of all email configured vCenter alerts?
Some times you need to audit these things because you missed an expected alert, audit or management are asking for it, or perhaps your just being proactive about your monitoring strategy.
What makes this ugly?
Once again there is no input validation.
Maybe alerts can be configured with multiple actions?
It overwrites any existing file with the same name.
Multiple addresses per alert could be cleaner and easer to read.
There are almost no comments.
# Set the vCenter we are connecting to
$vCenter = read-host 'vCenter FQDN'
# Connect to vCenter
Connect-VIServer -Server $vCenter
$alertActions = Get-AlarmAction | Where-Object {$_.ActionType -eq 'SendEmail'}
$emailAlerts = @()
foreach ($alert in $alertActions) {
$i = $null
$result = $null
$emailAlerts += [PSCustomObject]@{
'Name' = $alert.AlarmDefinition.Name
'Description' = $alert.AlarmDefinition.Description
'Enabled' = $alert.AlarmDefinition.Enabled
'sendto' = $(foreach($i in $alert.To) {$result = $result + "$i, "} ; $result.Trim(',',' '))
}
}
$emailAlerts | Export-Csv -Path "$env:USERPROFILE\Desktop\vCenter-Alerts.csv" -NoTypeInformation