I am trying to create a MetricAlert using the following script
Set-AzContext -Subscription "f0bXXXXXXX"
$action = Get-AzActionGroup -ResourceGroupName gze-actgrp-pd-rgp-001 -Name UWDevOps_PD
$actionID = New-AzActionGroup -ActionGroupId $action.id
#Get-AzMetricDefinition -ResourceId "/subscriptions/9ca95ff2-f1fd-447d-9130-9081d2ba12be/resourcegroups/gze-pdi203-pd1-rgp-001/providers/Microsoft.ContainerService/managedClusters/gze-pdi203-pd1-aks-isostr-001"
#set alert dim to pick the right options
$dim = New-AzMetricAlertRuleV2DimensionSelection -DimensionName "Name of the nodepool" -ValuesToInclude "pdi203pd101"
$severity = 1
$RGObject = "gze-pdi203-pd1-rgp-001"
$ResourceId = "/subscriptions/9caXXXXXXX/resourcegroups/gze-pdi203-pd1-rgp-001/providers/Microsoft.ContainerService/managedClusters/gze-pdi203-pd1-aks-isostr-001"
#set alert criteria and counter % Processor Time
$criteria = New-AzMetricAlertRuleV2Criteria -MetricName "node_disk_usage_percentage" -DimensionSelection $dim
-TimeAggregation average -Operator GreaterThan
-Threshold 90
Add-AzMetricAlertRuleV2 -Name "UWS-AKS203-ISOSTR-PD1-[Sev1-Error]-Cluster-DiskUtilization_Morethan90Percnt-V2-CT" -ResourceGroupName $RGObject
-WindowSize 01:00:00 -Frequency 01:00:00
-TargetResourceId $ResourceId -Condition $criteria
-ActionGroup $action.Id `
-Severity $severity
But then it fails here
$actionID = New-AzActionGroup -ActionGroupId $action.id
saying that
New-AzActionGroup is not recognized.
I have Az.Monitor 4.5 ver, AZ module ver 10.0.0 and windows PS ver 5.1 On reading some more blogs, it was made clear that New-AzActionGroup was not available in Az.MOnitor 4.5 and was only until ver 3.1.0. I tried to force install 3.1.0 using
Install-Module -Name Az.Monitor -RequiredVersion 3.0.1 -Force
but that did not install 3.0.1 either.
Firstly, check the current version of the
Az.Monitorinstalled module using below command.In any case, if you want to run the script with a different version than the one that is now installed, you must first unload the module with the
Remove-Modulecommand and then remove it with theuninstall-modulecommand.You can now use the other version of the module by reinstalling it using
Install-Module -Name xxxx -Requiredversion xxxx.Regarding your issue, after a workaround on it I found an alternative by installing
Az.Resourcesmodule. TheAz.Resourcesmodule, which is an accessible module for all Azure resources, contains theNew-AzActionGroupcommand.Use below commands in PowerShell to install and import the
Az.Resourcesmodule.Once it is done, I tried to execute the below commands related to the creation of action group and was successful as shown.
Alternatively, you can also use
az monitor action-group createCLI command in Azure bash to achieve your requirement without any conflicts.