I have a fairly simple requirement that is giving me some grief. I am trying to use the Get-AzMetric
cmdlet for PowerShell to extract average percent CPU usage metrics for an Azure Classic Cloud service. (This would be the same information as found in the portal under Monitoring -> Metrics.)
For my simple script I have isolated to the following:
Import-Module Az
Connect-AzAccount
Get-AzMetric `
-ResourceId "/subscriptions/8xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxf/...xxx" `
-TimeGrain 00:15:00 `
-MetricName "CpuPercentage"
The ResourceId
is copied and pasted directly from the Azure portal for the Classic Cloud service that I am trying to get the metrics for. From all appearances I am following the documentation correctly from Get-AzMetric (As.Monitor) | Microsoft Docs, however I keep getting a BadRequest
response that is not particularly insightful:
Get-AzMetric : Exception type: ErrorResponseException, Message:
Microsoft.Azure.Management.Monitor.Models.ErrorResponseException:
Operation returned an invalid status code 'BadRequest'
Any ideas on what might be wrong with my request?