New-AzActionGroupReceiver How to Set Up Voice Calls as a New Action Group?
February 6, 2020
As per the Microsoft documentation, I should be able to set up Azure Monitor Action Group with voice mail. I can easily do that from the portal. I wanted to do the same with PowerShell. The following code works as expected while setting up email and SMS.
import-module Az.Monitor
#Setting up action group
$resourceGroupName = "sqlalertdemo"
$emailaddress = 'first.lastname@domainName.com'
$phoneNumber = '1234567890'
$emailDBA = New-AzActionGroupReceiver -Name 'emailDBA' -EmailAddress $emailaddress
$smsDBA = New-AzActionGroupReceiver -Name 'smsDBA' -SmsReceiver -CountryCode '1' -PhoneNumber $phoneNumber
Set-AzActionGroup `
-Name 'notifydbadeadlock' `
-ResourceGroupName $resourceGroupName `
-ShortName 'deadlock' `
-Receiver $emailDBA,$smsDBA
When I add the code for the voicemail, I get an error message that parameters related to voicemail ‘cannot be found’.
$phoneDBA = New-AzActionGroupReceiver -Name 'phoneDBA' -VoiceCountryCode '1' -VoicePhoneNumber $phoneNumber -VoiceReceiver
New-AzActionGroupReceiver : A parameter cannot be found that matches parameter name 'VoiceCountryCode'. At line:1 char:56 + ... New-AzActionGroupReceiver -Name 'phoneDBA' -VoiceCountryCode '1' -Vo ... + ~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [New-AzActionGroupReceiver], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.Azure.Commands.Insights.ActionGroups.NewAzureRmActionGroupReceiverCommand
After searching online, I found numerous examples of the same code, but none was with voicemail set up. I submitted a question in StackOverflow. After two days, Ivan Yang responded with an answer. I needed PowerShell Version 6 (PowerShell Core) and Az.Monitor 1.5.0 version. After installing PowerShell Version 6.2.4, I was able to set up an action group with voicemail. See details in this StackExchange answer.
#Setting up action group
$resourceGroupName = "sqlalertdemo"
$emailaddress = 'abc@test.com'
$phoneNumber = 1234567890
$emailDBA = New-AzActionGroupReceiver -Name 'emailDBA' -EmailAddress $emailaddress
$smsDBA = New-AzActionGroupReceiver -Name 'smsDBA' -SmsReceiver -CountryCode '1' -PhoneNumber $phoneNumber
$phoneDBA = New-AzActionGroupReceiver -Name 'phoneDBA' -VoiceReceiver -VoiceCountryCode '1' -VoicePhoneNumber $phoneNumber
Set-AzActionGroup `
-Name 'notifydbadeadlock' `
-ResourceGroupName $resourceGroupName `
-ShortName 'deadlock' `
-Receiver $emailDBA,$smsDBA,$phoneDBA
One discrepancy I noticed between voicemail and the other two actions is the status column is empty. Whereas the other two mentions ‘Subscribed’. I do not what does that means. Checked documentation but unable to find anything.
My test works the same for all three, SMS, voice, and email.