Is there any other way to retrieve all the data (aggregation) when using Get-Azmetric command in powershell?
Description
Hi, does anyone able to retrieve all the data when using Get-AzMetric command in powershell? By default, it will only shows the Average but not the Minimum ,Maximum, Total and Count .. unless specify the Aggregation type on the command.
Would like to ask if it is possible to show all data in one run (Average, Maximum, Minimum, Total and Count). Thank you.
Here is the command I use. $CPU = Get-AzMetric -ResourceId $VMname.Id -TimeGrain 00:15:00 -StartTime $st -EndTime $et -MetricName "Percentage CPU" -DetailedOutput $CPU.Data

Script or Debug output
No response
Environment data
No response
Module versions
No response
Error output
No response
Thank you for your feedback. This has been routed to the support team for assistance.
Hi @Maeganda11 , for VM resource, aggregation type only supports average. Please reference https://learn.microsoft.com/en-us/azure/azure-monitor/essentials/metrics-supported#microsoftcomputevirtualmachines
Hi @maeganda11. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text “/unresolve” to remove the “issue-addressed” label and continue the conversation.
From this link, every metric supports only one Aggregation Type. But it's not correct. We can specify Aggregation type to get Maximum, Maximum and other aggregation type data. And if you call Get-AzMetricDefinition, you can get which aggregation type is supported for a specified resource. here is an example:
PrimaryAggregationType : Average
SupportedAggregationTypes : {Average, Maximum, Minimum}
So the link you provided only means the primary aggregation type. I also want to know if there is a way to get all supported aggregation type data in one call.
Hi @hanhsia , Azure PowerShell's implementation bases on public API and doc. For further clarification, please wait support team or service team's answer.
@maeganda11 Apologies for the late reply. Thanks for reaching out to us and reporting this issue. We are looking into this issue and we will provide an update.
@maeganda11 @hanhsia The Azure Monitor List Metrics REST API expects the aggregation query string parameter.
| aggregation | query | string | The list of aggregation types (comma separated) to retrieve. |
|---|
When I invoked the below REST API directly as shown below:
https://management.azure.com//subscriptions/XXXXXXXX/resourceGroups/Allrg/providers/Microsoft.Compute/virtualMachines/MYVMNAME/providers/Microsoft.Insights/metrics?api-version=2018-01-01&aggregation=minimum%2Caverage%2Cmaximum
I got the desired output see below:

Could you try to invoke the above REST API from powershell and check if that helps. ? Also refer this sample PS script in this thread.
Hi @maeganda11. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text “/unresolve” to remove the “issue-addressed” label and continue the conversation.
Hi @maeganda11, since you haven’t asked that we “/unresolve” the issue, we’ll close this out. If you believe further discussion is needed, please add a comment “/unresolve” to reopen the issue.