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

Lyly Vuu 5 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.
9,013 questions
{count} vote

2 answers

Sort by: Most helpful
  1. Anonymous
    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.

  2. Boehnke, Christian (RIS-KOP) 0 Reputation points
    2025-04-25T20:51:42.5033333+00:00

    I would also like to know how to programmatically, conclusively figure out "generation status" for all the VM instance types we are running.

    It looks like the "retired" status is available only in documention,
    https://learn.microsoft.com/en-us/azure/virtual-machines/sizes/retirement/retired-sizes-list

    and separate doc for "capacity limited" and "next-gen available".
    https://learn.microsoft.com/en-us/azure/virtual-machines/sizes/previous-gen-sizes-list

    Does not look like this is available as an attribute (of VM SKU, or the like), or even as a table we could ingest.

    Guess the 2 lists are very short, so I generate my own status table.

    I have had some limited success with coaxing answers out of Azure copilot, e.g.

    > What is the retirement status of a VM of type Standard_F16?
     Copilot / AI-generated content may be incorrect
    'The Standard_F16 VM type is part of the F-series, which is currently classified as "Next-gen available." This means it is not retired and can still be used, although it is recommended to consider migrating to newer generation sizes when possible.'
    

    ... but any attempt to get this as a table - or better yet, query - have failed me so far.

    Closest I got is first 5:

    > List all VM as count by instance type in use across all subscriptions, list their generation in terms of retired, previous-gen, next-gen available, or capacity limited
    Copilot said:
    Here is a summary of the virtual machines in use across all subscriptions, categorized by instance type:
    Instance Type Count. Generation Status
    Standard_E2ds_v4 1 Previous-gen, Next-gen available
    Standard_E4bds_v5 1 Current-gen
    Standard_D8s_v5 1 Current-gen
    Standard_D4ls_v5 1 Current-gen
    Standard_E64ads_v5 1 Current-gen
    

    No option to expand, nor query to produce the results.

    0 comments No comments

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.