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.