How to programmatically determine whether a VM size is previous-gen

Lyly Vuu 0 Reputation points
2024-10-01T10:06:27.4866667+00:00

This documentation describes VM series are that previous-gen: https://learn.microsoft.com/en-us/azure/virtual-machines/sizes/previous-gen-sizes-list

For every VM in our tenant, we are looking to programmatically determine the VM "status" (e.g. capacity limited, next-gen available, or retired). There doesn't appear to be an API that will return this information. Please advise on the best method to obtain this information. Thank you in advance.

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

1 answer

Sort by: Most helpful
  1. Srinud 2,610 Reputation points Microsoft Vendor
    2024-10-08T08:07:25.7133333+00:00

    Hi Lyly Vuu,

    As of now, there is no direct API that provides the specific statuses of "next-gen available," "capacity-limited," or "retired" for VMs.
    However, you can take the following approach to monitor VM sizes programmatically.
    You can use Azure Resource Graph (ARG) to programmatically query all VMs in your tenant and gather their size information. Then, you can cross-reference the sizes with known lists of previous-gen or retiring VM series provided by Microsoft.

    Resources
    | where type == "microsoft.compute/virtualmachines"
    | project name, location, properties.hardwareProfile.vmSize
    

    You can use this to check the VM sizes and compare them against the official Previous Generation Sizes list.
    You can also script a process to check available VM sizes in specific regions using the Azure CLI:

    az vm list-sizes --location <region>
    

    Azure Advisor provides recommendations, including on VM retirement and best practices. You can query Azure Advisor using the Azure Advisor REST API to get recommendations regarding VM sizes that are no longer best suited for use.
    If you are still facing any issue, please let us know in the comments. We are glad to help you.

    If this information is helpful, we would appreciate it if you could click the "Accept answer and Upvote" on this post.

    Thank you.

    1 person found this answer 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.