Skip to content

[Feature]: Invoke-AzCostManagementQuery improve output #27735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
o-l-a-v opened this issue May 12, 2025 · 2 comments
Open

[Feature]: Invoke-AzCostManagementQuery improve output #27735

o-l-a-v opened this issue May 12, 2025 · 2 comments
Labels
Cost Management - Query All issues in cost management and Consumption for query API associated to tags, dimensions and forec customer-reported feature-request This issue requires a new behavior in the product in order be resolved. Service Attention This issue is responsible by Azure service team.

Comments

@o-l-a-v
Copy link

o-l-a-v commented May 12, 2025

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.

@o-l-a-v o-l-a-v added feature-request This issue requires a new behavior in the product in order be resolved. needs-triage This is a new issue that needs to be triaged to the appropriate team. labels May 12, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot added customer-reported needs-triage This is a new issue that needs to be triaged to the appropriate team. and removed needs-triage This is a new issue that needs to be triaged to the appropriate team. labels May 12, 2025
@isra-fel isra-fel added Service Attention This issue is responsible by Azure service team. Cost Management - Query All issues in cost management and Consumption for query API associated to tags, dimensions and forec and removed needs-triage This is a new issue that needs to be triaged to the appropriate team. labels May 16, 2025
Copy link
Contributor

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @ccmixpdevs.

1 similar comment
Copy link
Contributor

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @ccmixpdevs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cost Management - Query All issues in cost management and Consumption for query API associated to tags, dimensions and forec customer-reported feature-request This issue requires a new behavior in the product in order be resolved. Service Attention This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

2 participants