How do I use Graph or PS queries to get list of all VMs attached to a Reservation, and all VMs that are not (paygo)?

Chris Moceri 10 Reputation points
2023-12-04T19:26:39.0966667+00:00

I am trying to find ways of getting a list of all Azure VMs across my subscriptions that ARE using Reserved Instances we have purchased, and a list of all that are not using RIs (paygo).

We are trying to figure out the details of all VMs that are still Paygo in order for us to potentially resize them prior to purchasing additional RIs. This is urgently needed.

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
8,985 questions
{count} votes

1 answer

Sort by: Most helpful
  1. kobulloc-MSFT 26,721 Reputation points Microsoft Employee Moderator
    2023-12-06T01:32:58.9566667+00:00

    Hello, @Chris Moceri ! I spoke with the virtual machine team and confirmed that this is not tracked at the VM level but rather as a product of billing. I'll go into more detail as to how you can get the information you need below.

    How do I review VM reservation utilization and plan for future VM reservations when looking at pay-as-you-go use?

    Unlike Azure Hybrid Benefit discounts that are associated with a virtual machine, VM reservations look at your total VM resource usage and apply a discount to your bill for qualifying use. This allows different VMs to qualify for reservation use as fractional hours when needed. As a result, there is no property on a VM that tracks reservation use however you can review utilization through your bill and plan for future reservation purchases through a number of different approaches which we'll cover below.

    Get details on all VM utilization by a reservation

    After purchasing a reservation, you can view the utilization at the resource level by starting at the portal and going to reservations. From there, you will see a list of reservations as well as the utilization. By clicking on a reservation, you can see the utilization details including the VM resources that were used. In addition to the portal, you can use APIs, PowerShell, and Azure CLI in addition to Power BI options.

    User's image

    For a PowerShell example with multiple subscriptions, Virtual Geek has a script you can leverage:

    http://vcloud-lab.com/entries/microsoft-azure/powershell-get-the-list-of-azure-reservations-virtual-machines-instances

    For individual pay-as-you-go subscriptions, you can use the statement section of the CSV file for VMs to determine usage.

    User's image

    Determining which reservation to purchase

    First, you'll need to view and download your Azure usage and charges. When analyzing usage for a VM reserved instance purchase, apply the following filters on your usage data to narrow down to eligible VM usage:

    • Filter MeterCategory to Virtual Machines.
    • Get ServiceType information from AdditionalInfo. The information suggests the right VM size. For example, D2s_v3.
    • Use the ResourceLocation field to determine the usage data center.

    Ignore resources that have less than 24 hours of usage in a day.

    Reservation purchases calculated by the recommendations engine are shown on the Recommended tab in the Azure portal and reservation purchase recommendations are available in Azure Advisor.

    Image showing recommendations


    I hope this has been helpful! Your feedback is important so please take a moment to accept answers.

    If you still have questions, please let us know what is needed in the comments so the question can be answered. Thank you for helping to improve Microsoft Q&A!

    User's image


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.