In my previous blog posts, I wrote about how simple PowerShell scripts can help speed up daily tasks for Azure administrators, and how you can convert them to your own API.
One of these tasks is to monitor and manage the costs of the resources deployed in the Azure environment. This task is crucial for keeping expenses in check and optimizing the usage of resources. However, managing the costs of multiple resources can be a daunting task and can take up a lot of time.
To help with this task, Azure provides Azure Cost Management and Billing, a tool that helps you analyze, manage, and optimize your Azure costs. But sometimes, we need to quickly check the cost of specific resources. Drilling down through the billing and trying to identify that specific resource can be time-consuming.
This is where the PowerShell script for retrieving cost data for a Resource Group comes in handy. I wrote this simple Azure Function to allow me to retrieve cost data for a specified Resource Group within a specified time range. This data can then be used to analyze the costs of the resources deployed in the Resource Group and optimize their usage.
Please note that some Azure Billing related commandlets, including
Get-AzConsumptionUsageDetail currently do not work with Azure Plan Subscriptions or Sponsored Subscriptions, and it will return BadRequest error. It works with Pay As You Go.
You can also convert this to Azure Function API and have it available to you at all times. Check out my previous article to learn how to Create Your Own PowerShell APIs for Azure Governance with Azure Function App and how that can be useful for your daily Azure Administrator tasks.
I hope this was useful. Keep clouding around.