I was running a powershell script and it was throwing the error
##[error]The term 'New-AzActionGroupReceiver' is not recognized as the name of a cmdlet, function, script file, or operable program.
As it belongs to the module, Az.Monitor, I tried installing it before the command
"New-AzActionGroupReceiver -Name $name -EmailReceiver -EmailAddress $item"
is executed. I installed the module using
Install-Module -Name Az.Monitor -Force
the error still remained the same
I was running the script over an azure devops pipeline, despite my attempt to install the module and deploy, it failed
2
Answers
Looks like the issue is with the version,thanks for the inputs @Vinay B the cmdlets which we have been using might be deprecated, we can use the below commands, instead of the commands which we have used before, i.e., use
New-AzActionGroupEmailReceiverObject -Name $name -EmailAddress $item
instead of
New-AzActionGroupReceiver -Name $name -EmailReceiver -EmailAddress $item
and use
New-AzActionGroup -Name $ActionGroupName -ResourceGroup $ResourceGroupName -ShortName $ActionGroupShortName -Location $DefaultLocation -EmailReceiver $actionGroupEmailReceiver
instead of
Set-AzActionGroup -Name $ActionGroupName -ResourceGroup $ResourceGroupName -ShortName $ActionGroupShortName -Location $DefaultLocation -EmailReceiver $actionGroupEmailReceiver
The error message "The term ‘New-AzActionGroupReceiver’ is not recognized" indicates that PowerShell doesn’t recognize the command, likely because the corresponding module isn’t installed or properly loaded or the version of the powershell Installed.
Since you followed the steps to Re-Installing the module this may also be due to version of PowerShell provider.
Follow the command mentioned below to overcome the issue you mentioned.
check with the version you’re using
$PSVersionTable.PSVersion
Ensure that you installed the module correctly. You can verify this by running the following command
Get-InstalledModule -Name Az.Monitor
If the module is not listed, try reinstalling it
Install-Module -Name Az.Monitor -Force
After installing the module, make sure you import it into your PowerShell session. Use the following command
Import-Module -Name Az.Monitor
To verify the command is recognizable follow the command below
Get-Command -Name New-AzActionGroupReceiver
Now follow the command below to provision the requiement youre looking for
Import-Module Az.Monitor
$name = "vinay kumar"
$item = "your mail ID"
New-AzActionGroupReceiver -Name $name -EmailReceiver -EmailAddress $item