How can I create a PowerShell script to report costs for Azure Resource Groups?

0
0
Asked By SunnyDaze123 On

Hi everyone! I'm trying to put together a PowerShell script that can generate a report showing the actual costs of a specific resource group over a set period of time. I've been experimenting with various methods, but I haven't been able to get it right, and even AI hasn't been much help in generating the correct script. Any assistance would be appreciated! Thanks in advance!

2 Answers

Answered By ResourceGuru94 On

Could you share what you've tried already? It would really help you get more tailored guidance. Not that anyone will give you the exact script right away, but we can point you in the right direction!

SunnyDaze123 -

I've attempted several approaches but ended up deleting and starting over. I tried this one with some results, but it didn't show the actual costs:

"Invoke-AzCostManagementQuery -Scope 'subscriptions/$subscriptionId/resourceGroups/$resourceGroupName' -Timeframe MonthToDate -Type Usage -DatasetGranularity 'Daily'"

And also:

"az consumption usage list --resource-group $resourceGroupName --query '[].{Name:name, Cost:cost}' --output table".

Answered By TechWanderer99 On

Have you considered using the cmdlet from the Azure Cost Management module? You can check out how it works here: [Cost Management Export](https://learn.microsoft.com/en-us/powershell/module/az.costmanagement/get-azcostmanagementexport?view=azps-14.3.0). Give it a shot and see if it fits your needs!

SunnyDaze123 -

I tried that, but I didn’t get any output when running the script. I can see everything I need through the GUI.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.