Fetch Azure VM Size List along with VM Type

899 Views Asked by At

Need help in fetching the list of Azure VM's along with there type/category(e.g. General, Compute Intensive etc.) refer https://learn.microsoft.com/en-us/azure/virtual-machines/sizes

I understand that the Azure API provides the list VM's)Size, configuration etc.) supported in a subscription for a given region refer https://learn.microsoft.com/en-us/rest/api/azureml/workspacesandcomputes/virtualmachinesizes/list

However we want to list VM's somewhat similar to below

enter image description here

1

There are 1 best solutions below

0
On

If you want to list azure vm resource sku with C#, please refer to the following steps:

  1. Create a service principal and assign Contributor role to the sp
az login
#create sp and assign Contributor role at subscription level
az ad sp create-for-rbac -n "your service principal name"

enter image description here

  1. Code. I use the package Microsoft.Azure.Management.Fluent and Microsoft.Azure.Management.ResourceManager.Fluent
 string clientId = "<sp appID>";
            string clientSecret = "<sp passowrd>";
            string tenantId = "";
            string subscriptionId = "";
            var credentials = SdkContext.AzureCredentialsFactory
                .FromServicePrincipal(clientId,
                    clientSecret,
                    tenantId,
                    AzureEnvironment.AzureGlobalCloud);
            var azure = Microsoft.Azure.Management.Fluent.Azure
                        .Configure()
                        .WithLogLevel(HttpLoggingDelegatingHandler.Level.BodyAndHeaders)
                        .Authenticate(credentials)                       
                        .WithSubscription(subscriptionId);

            IPagedCollection<IComputeSku> skus = await azure.ComputeSkus.ListbyRegionAndResourceTypeAsync(Region.AsiaSouthEast, ComputeResourceType.VirtualMachines);

            // process data according to your need
                   //get B-series VMs size
                   var newSkus =skus.Where(sku => sku.Inner.Family == "standardBSFamily").ToList();

For more details, please refer to the sample and API