VMware Cloud Community
cheeweng
Contributor
Contributor

Edit alarm To: email address

Hi guys 

I have a script which list all alarm with email address. Please help how do i enhance it to list it and edit with new correct email address. Thanks in advance for helping.

 

ForEach ($alarm in Get-AlarmDefinition) {
ForEach ($action in (Get-AlarmAction -AlarmDefinition $alarm)) {
If ($action.ActionType -eq 'SendEmail') {
Write-Host "Alarm name is $alarm"
Write-Host "Alarm To Recipients is $($action.To)"
Write-Host "Alarm Email Subject is $($action.Subject)"
Write-Host ""
}
}
}

 

 

Alarm name is Datastore usage on disk
Alarm To Recipients is user1@domainname,user2@domainname,user3@domainname
Alarm Email Subject is Alarm {alarmName} on Datastore : {targetName} is {newStatus}

 

0 Kudos
6 Replies
LucD
Leadership
Leadership

You can use the method provided in Re: vSphere 6.5 - Looking for way to mass update t... - VMware Technology Network VMTN
Instead of doing a Get-AlarmDefinition for all Alarms, you just do it for the specific Alarm (Name parameter) you want to update.


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

0 Kudos
cheeweng
Contributor
Contributor

Thanks LucD

 

The script is working well , unfortunately it clear all my existing alarm due to wrong syntax into email field 

 

$newEmail = 'my.new@email.address;my.new2@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

    }

}

 

 

 

Manage to change email address with correct typo syntax

$newEmail = 'my.new@email.address,'my.new2@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

    }

}

 

 

0 Kudos
cheeweng
Contributor
Contributor

Hi ,

How do i put in multiple email address ? i tried and dont seem to work with correct syntax 

0 Kudos
LucD
Leadership
Leadership

There have been reports of bugs when entering multiple email addresses.
The best workaround is to create an individual action for each email address.


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

0 Kudos
OT_dmenafro
Contributor
Contributor

Try as this: 'my.new@email.address,my.new2@email.address'

Your line looks to have an extra ' : 'my.new@email.address,'my.new2@email.address'

I saw initially you were using the semicolon and came to suggest using a comma, but noticed you're doing that as well.

I came to the forums to ask a similar question and found they're aware of an issue with multiple addresses per:

https://kb.vmware.com/s/article/2150106

https://kb.vmware.com/s/article/2075153

 

Their solution is to make multiple single email notifications, use an email distro group, or a comma.

I ran across this issue when scheduling a task in vcenter to take a snapshot. While I understand the issue exists and may be challenging to patch. It would be nice if they could update the example in the user interface to use a comma instead of a semi colon.

Hopefully they'll fix the issue 🙂

0 Kudos
ChrisLeblanc
Contributor
Contributor

I have been able to put multiple email addresses using the format below. The trick for me is that the $newEmail variable needs to be an array with all the emails you want in it. When I did that, it showed up as ; separated in the alarm.

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

    }

0 Kudos