Need Help with PowerShell Script for Resource Group Cost Reporting

0
2
Asked By CuriousCoder99 On

Hey everyone! I'm trying to put together a PowerShell script that can help me generate a report showing the current cost of a specific resource group over a given date range. I've been experimenting with various methods, but I just can't seem to hit the mark. Even AI hasn't been much help in getting the right script for me. Any suggestions would be greatly appreciated! Thanks in advance!

3 Answers

Answered By ScriptGuru22 On

What have you tried so far? If you share your current attempts, it will be easier for us to guide you. You might not get an exact answer, but we can point you in the right direction!

CuriousCoder99 -

I've tried multiple approaches and ended up deleting and redoing quite a bit. I experimented with this code, but it still doesn’t show the actual cost:

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

I also tried:
```shell
az consumption usage list --resource-group $resourceGroupName --query '[].{Name:name, Cost:cost}' --output table
```
And that didn't work either.

Answered By HelpfulTechie42 On

You might want to try using the `Get-AzCostManagementExport` command. It could be really useful for this type of task. You can find more details on it in the official documentation [here](https://learn.microsoft.com/en-us/powershell/module/az.costmanagement/get-azcostmanagementexport?view=azps-14.3.0). Good luck!

CuriousCoder99 -

Unfortunately, I didn't get any output when I ran that script. I have everything I need in the GUI for cost checking.

Answered By CloudExplorer77 On

One interesting trick is to go into the Azure portal, navigate to your resource group, and use the developer tools in your browser. Check the cost analysis section and look at the network tab for the API calls it makes. You can then convert these into PowerShell commands!

CuriousCoder99 -

That sounds like a unique approach! I might start with the more straightforward methods first, but I'll keep this in mind if I get stuck.

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.