Quickly Configure vCenter Alarms with PowerCLI

less than 1 minute read

I found the below snippets on VirtIRL.

This configures all vCenter alarms to send an email:

Get-AlarmDefinition | New-AlarmAction -Email -To '[email protected]'

Now you can create an alarm trigger to send an email when the monitored item changes from green to yellow as well. The default alarm action automatically creates the alert for yellow to red (above example).

Get-AlarmDefinition | Get-AlarmAction -ActionType SendEmail | where-object {$_.To -like '[email protected]'} | New-AlarmActionTrigger -StartStatus 'Green' -EndStatus 'Yellow'

To add other transitions (red to yellow, yellow to green) you can just change the -StartStatus and -EndStatus to the necessary values.

To see all Alarms configured to send to a certain email address along with triggers:

Get-AlarmDefinition | Get-AlarmAction -ActionType SendEmail | Where-Object {$_.To -like '[email protected]'} | Select AlarmDefinition,To,Trigger

To remove all SendEmail AlarmActions for a particular email address:

Get-AlarmDefinition | Get-AlarmAction -ActionType SendEmail | where-object {$_.To -like '[email protected]'} | Remove-AlarmAction