Open
Description
Description of the new feature
The output of Invoke-AzCostManagementQuery
is not intuitive to work with. Example:
$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:
{
"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:
$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.
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
microsoft-github-policy-service commentedon May 16, 2025
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @ccmixpdevs.
microsoft-github-policy-service commentedon May 16, 2025
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @ccmixpdevs.