How to Fetch Azure Subscription Resource Cost via Code with Customization?

Jyoti Teli (BLR GSS) 60 Reputation points
2025-01-20T10:25:45.43+00:00

Hello,

I want to fetch the cost of all resources within a specific Azure subscription programmatically, similar to how it's displayed on the Azure portal. I'm looking for a solution that will allow me to:

  1. Retrieve the exact cost data for all resources in my subscription, including details like resource usage and pricing.
  2. Implement some customization in the data, such as filtering specific resources or applying custom parameters.
  3. Export the results in JSON format or another easily parsable format.

Can anyone guide me on how to achieve this using code? Specifically, I'm looking for options using power shell, Azure CLI that can help me achieve this. Any examples or pointers would be greatly appreciated!

Thank you!

Azure Cost Management
Azure Cost Management
A Microsoft offering that enables tracking of cloud usage and expenditures for Azure and other cloud providers.
2,984 questions
{count} votes

Accepted answer
  1. Ashok Gandhi Kotnana 3,120 Reputation points Microsoft Vendor
    2025-01-20T15:44:14.4233333+00:00

    Hi @Jyoti Teli (BLR GSS) ,

    Welcome to Microsoft Q&A Forum, thank you for posting your query here!

    To fetch detailed cost data for all resources in a specific Azure subscription, you can use the

    Below is the reference links that will help you to take it forward using REST API.

    https://learn.microsoft.com/en-us/rest/api/cost-management/generate-detailed-cost-report/create-operation?view=rest-cost-management-2024-08-01&tabs=HTTP#code-try-0

    let us know if you have any further queries. I’m happy to assist you further.  

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.