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?

# 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