Open
Description
openedon Sep 30, 2024
Type of issue
Code doesn't work
Feedback
People would use Invoke-AzCostManagementQuery
to retrieve cost information, but the listed examples do not return any actual cost data. This is due to the way the underlying API is designed: if you don't request any aggregation
s, then you just get empty response rows.
For contrast, here's an API request as sent by the Azure Portal. Notice the aggregation
property.
POST https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.CostManagement/query?api-version=2021-10-01&$top=5000
{
"type": "ActualCost",
"dataSet": {
"granularity": "None",
"aggregation": {
"totalCost": {
"name": "Cost",
"function": "Sum"
},
"totalCostUSD": {
"name": "CostUSD",
"function": "Sum"
}
},
"grouping": [
{
"type": "Dimension",
"name": "ResourceGroupName"
},
{
"type": "Dimension",
"name": "ChargeType"
},
{
"type": "Dimension",
"name": "PublisherType"
}
]
},
"timeframe": "Custom",
"timePeriod": {
"from": "2024-09-01T00:00:00+00:00",
"to": "2024-09-30T23:59:59+00:00"
}
}
Mimicking that API call, here's an example for Invoke-AzCostManagementQuery
that does return cost data:
Invoke-AzCostManagementQuery -Scope /subscriptions/00000000-0000-0000-0000-000000000000 -Timeframe MonthToDate -Type ActualCost -DatasetGranularity 'Monthly' -DatasetAggregation @{ 'totalCost' = @{ 'name' = 'Cost' } }
Column Row
------ ---
{Cost, BillingMonth, Currency} {1.54425705929919 01 Sept 2024 00:00:00 EUR}
Could you update the docs to list more helpful examples?
Related: #20749
Page URL
Content source URL
Author
Document Id
3dff2f6a-7cc0-e478-2079-8a417fc895dd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment