VMware Cloud Community
kcameron73
Contributor
Contributor

vSphere 6.5 - Looking for way to mass update the email addresses on my alarm actions

I posted this in a general forum and it was suggested I re-post it here:

Hello there,

We have some 200 alarm definitions and I need to update the email addresses under the action for just about all of them in 3 different environments.  Is there any way to do this in bulk or by line command script rather than A LOT of clicking.

Thanks,

Kevin

1 Reply
LucD
Leadership
Leadership

Unfortunately there is no Set-AlarmAction cmdlet, which means we have to add/remove an action to update the To field

Something like this

$newEmail = 'my.new@email.address'

foreach($alarm in Get-AlarmDefinition){

    foreach($action in (Get-AlarmAction -AlarmDefinition $alarm -ActionType SendEmail)){

        $sAction = @{

            AlarmDefinition = $alarm

            Email = $true

            Subject = $action.Subject

            To = $newEmail

            Body = $action.Body

            Cc = $action.Cc

        }

        New-AlarmAction @sAction

        Remove-AlarmAction -AlarmAction $action -Confirm:$false

    }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference