When trying to create a memory alert I get the following error:
Add-AzMetricAlertRuleV2 : Exception type: ErrorResponseException, Message: You can't define a scope that is different from the selected target resource type.
Do I have something wrong with the memory metric here?
Issue script & Debug output
It's going to take several hours to sanitize this debug output. The only information it gave was the same error I'm getting. If it's really needed, I'll sit down and sanitize but I don't particularly have that time right now
WARNING: Upcoming breaking changes in the cmdlet 'Resolve-AzError' :
The `Resolve-Error` alias will be removed in a future release. Please change any scripts that use this alias to use
`Resolve-AzError` instead.
Note : Go to https://aka.ms/azps-changewarnings for steps to suppress this breaking change warning, and other
information on breaking changes in Azure PowerShell.
HistoryId: 5
Message : Exception type: ErrorResponseException, Message: You can't define a scope that is different from the
selected target resource type. Activity ID: 5fca82a6-8b32-43bc-89b0-e06b636ca487., Code: BadRequest,
Status code:BadRequest, Reason phrase: BadRequest
StackTrace : at Microsoft.Azure.Commands.Insights.MonitorCmdletBase.ExecuteCmdlet()
at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception : System.Management.Automation.PSInvalidOperationException
InvocationInfo : {Add-AzMetricAlertRuleV2}
Line : Add-AzMetricAlertRuleV2 -Name " Memory Utilization Over 95 Percent" -ResourceGroupName
$ActionGroup.ResourceGroupName -WindowSize 0:5 -Frequency 0:5 -TargetResourceType
"Microsoft.Computer/virtualMachines" -TargetResourceScope "$($Target.Id)" -TargetResourceRegion
"$($Target.Location)" -Condition $Condition -ActionGroup $AGID -Severity 0
Position : At line:5 char:1
+ Add-AzMetricAlertRuleV2 -Name " Memory Utilization Over 95 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 5
Message : Operation returned an invalid status code 'BadRequest'
StackTrace : at Microsoft.Azure.Management.Monitor.MetricAlertsOperations.<CreateOrUpdateWithHttpMessagesAsync>d
__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Management.Monitor.MetricAlertsOperationsExtensions.<CreateOrUpdateAsync>d__7.Mo
veNext()
Exception : Microsoft.Azure.Management.Monitor.Models.ErrorResponseException
InvocationInfo : {Add-AzMetricAlertRuleV2}
Line : Add-AzMetricAlertRuleV2 -Name " Memory Utilization Over 95 Percent" -ResourceGroupName
$ActionGroup.ResourceGroupName -WindowSize 0:5 -Frequency 0:5 -TargetResourceType
"Microsoft.Computer/virtualMachines" -TargetResourceScope "$($Target.Id)" -TargetResourceRegion
"$($Target.Location)" -Condition $Condition -ActionGroup $AGID -Severity 0
Position : At line:5 char:1
+ Add-AzMetricAlertRuleV2 -Name " Memory Utilization Over 95 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 5
The Azure PowerShell team is listening, please let us know how we are doing: https://aka.ms/azpssurvey?Q_CHL=ERROR.
Description
When trying to create a memory alert I get the following error:
Add-AzMetricAlertRuleV2 : Exception type: ErrorResponseException, Message: You can't define a scope that is different from the selected target resource type.
Here is the following code I use:
The weird thing is, I can set CPU and disk alerts just fine on the same server in the same group. Below is the code I used for CPU:
Do I have something wrong with the memory metric here?
Issue script & Debug output
Environment data
Module versions
Error output