I am trying to do consumption by location using:
az login
$consumpCost = az consumption usage list --query "[?
type=='Microsoft.Consumption/usageDetails' &&
instanceLocation=='northcentralus'].pretaxCost" --output json | ConvertFrom-Json
$consumpCost = $consumpCost -split "`n" | ForEach-Object { [decimal]$_ }
$combcost = $consumpCost | Measure-Object -Sum | Select-Object -ExpandProperty Sum
Write-Host "Total Cost: $combcost"
But it always comes out 0.00 in total ie $combcost . Can anyone help as to why it is coming out as $0.00 ?
I have removed the unnecessary lines of code such as
splitoperator and place holders as it might lead to conflicts in displaying the correct results.Modified Script:
Note: At times, if the
Total Costappears as0, it doesn't necessarily indicate an issue with the results. It could be that the specifiedlocationin your query is not actively used by any users or applications within the particular enterprise agreement. In such scenarios, consider trying other locations to validate the details.After I executed the above code in my environment, I was able to retrieve the cost consumption details successfully.
Output: