Azure / Azure/azure-powershell
Bad examples for `Invoke-AzCostManagementQuery`
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 51
Description
### 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
```
```json
{
"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
https://learn.microsoft.com/en-us/powershell/module/az.costmanagement/invoke-azcostmanagementquery?view=azps-12.3.0&viewFallbackFrom=azps-10.4.1
### Content source URL
https://github.com/Azure/azure-powershell/blob/main/src/CostManagement/CostManagement/help/Invoke-AzCostManagementQuery.md
### Author
@mikefrobbins
### Document Id
3dff2f6a-7cc0-e478-2079-8a417fc895dd
Contributor guide
Research direction
Read src/CostManagement/CostManagement/help/Invoke-AzCostManagementQuery.md and compare its current examples with the API request and working command shown in this issue. Update the examples so they request aggregations and return cost data, then verify the documented commands and output against the related guidance in issue #20749.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, powershell
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100