Azure / Azure/azure-powershell
[Feature]: `Invoke-AzCostManagementQuery` improve output
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 51
Description
### Description of the new feature
The output of `Invoke-AzCostManagementQuery` is not intuitive to work with. Example:
```pwsh
$null = Add-Member -InputObject $Subscription -Force -NotePropertyName 'ConsumptionTwoWeeksAgo' -NotePropertyValue (
Invoke-AzCostManagementQuery -WhatIf:$false -DatasetAggregation @{
'totalCost' = @{
'name' = [string] 'Cost'
'function' = [string] 'SUM'
}
} -Type 'ActualCost' -Timeframe 'Custom' `
-Scope ('/subscriptions/{0}' -f $Subscription.'Id') `
-TimePeriodFrom $StartOfTwoWeeksAgo.ToString('o') `
-TimePeriodTo $EndOfTwoWeeksAgo.ToString('o') 6>$null
)
```
Results to JSON:
```json
{
"Column": [
{
"Name": "Cost",
"Type": "Number"
},
{
"Name": "Currency",
"Type": "String"
}
],
"ETag": null,
"Id": null,
"Location": null,
"Name": null,
"NextLink": null,
"ResourceGroupName": null,
"Row": [
[
"9,126E-05",
"DKK"
]
],
"Sku": null,
"Tag": {},
"Type": null,
"Property": {
"Column": [
{
"Name": "Cost",
"Type": "Number"
},
{
"Name": "Currency",
"Type": "String"
}
],
"NextLink": null,
"Row": [
[
"9,126E-05",
"DKK"
]
]
}
}
```
To get the sum and currency one have to do something like this:
```pwsh
$null = Add-Member -InputObject $Subscription -Force -NotePropertyMembers @{
'Currency' = [string]$(Try{$Subscription.'ConsumptionLastWeek'.'Row'[0][1]}Catch{''})
'SumLastWeek' = [double]::Parse($(Try{$Subscription.'ConsumptionLastWeek'.'Row'[0][0]}Catch{0}))
'SumTwoWeeksAgo' = [double]::Parse($(Try{$Subscription.'ConsumptionTwoWeeksAgo'.'Row'[0][0]}Catch{0}))
}
```
### Proposed implementation details (optional)
Make sum and currency into properties, instead of having to index rows as an array.
Contributor guide
Assessment
This issue has not been assessed yet.