0

Good Morning,

I've tried to get current usage and forecast for multiple subscriptions (just the $ amount for one and the other - not interested in detailed results). The best/only way I've found is to use "Get-AzConsumptionBudget" however for multiple subscriptions I get result 0, but when I navigate in Portal there is actual consumption (sometimes quite big).

I was wondering if there is a way to get current usage and forecasted (so exactly what is shown on Portal/Subscription overview) in Powershell?

Thank you

Adam J
  • 13
  • 2

2 Answers2

1

As @Ked-Mardemootoo mentioned current usage can be achieved with: Get-AzConsumptionUsageDetail -BillingPeriodName $CurrentMonth | Measure-Object PretaxCost -Sum

Adam J
  • 13
  • 2
0

Get-AzConsumptionBudget will only provide you budget information. It's showing zero because you have not configured any budget information for these subscriptions. What you should be using is the Get-AzConsumptionUsageDetail.

However, based on the findings in the comment section below, if budgets are set for all subscriptions, it seems that using Get-AzConsumptionBudget will provide the budget consumption.

For the cost forecast - unfortunately Powershell or Az CLI do not yet support that. If you still need to get it, you can try the REST API for forecast but it will require a bit of work, including creating a service principal.

Ked Mardemootoo
  • 1,480
  • 1
  • 5
  • 19
  • Technically get-AzConsumptionBudget will show current usage...but as you said, only when budget is configured (with .CurrentSpend). Also, good point on the Get-AzConsumptionUsageDetail - it can show fairly accurate current usage with: `Get-AzConsumptionUsageDetail -BillingPeriodName $CurrentMonth | Measure-Object PretaxCost -Sum'` Unfortunately still cannot figure out how to get forecasted – Adam J Jun 01 '21 at 12:08
  • Yes you're right - it will only show the current usage after you configure the budget for that subscription since budget consumption is part of budget information. I have updated my answer with some more information about the REST API for forecast. If you're satisfied with the answers/information, give it an upvote or mark as answer - whichever applicable! Thanks :) – Ked Mardemootoo Jun 02 '21 at 17:43