Powershell script to get the list of VM SKUs with certain capabilites (Get-AzComputeResourceSku)

1.1k Views Asked by At

I wanted to write a PS Script to get the list of SKUs in a region for which certain capabilities (such as MaxDataDiskCount, CpuArchitectureType etc) are enabled.

In my case I wanted the list of VM SKUs in a given region with UltraSSDAvailable capability

Get-AzComputeResourceSku | Where-Object { $.Locations -contains "eastus2euap" -and $.ResourceType.Contains("virtualMachines") }

This prints many lines and the Capability field is an array of objects. I wanted to apply filter on them and shortlist the VM SKUs.

1

There are 1 best solutions below

0
Ankitha Pilli On

I could come up with the below PS Script

$Region = "westus" # change region here
$type = "virtualMachines"

$VMSKUs = Get-AzComputeResourceSku | Where-Object { $_.Locations -contains "eastus2euap" -and $_.ResourceType.Contains("virtualMachines") }

$OutTable = @()

foreach ($SkuName in $VMSKUs)
        {       
            foreach($capability in $SkuName.Capabilities)
            {
                if($capability.Name -contains "UltraSSDAvailable")
                {
                    if($capability.Value -eq "true")
                    {
                        foreach($insideCapability in $SkuName.Capabilities)
                        {
                            if($insideCapability.Name -contains "MaxDataDiskCount")
                            {
                                
                                $OutTable += New-Object PSObject -Property @{
                                                                 "Name" = $SkuName.Name
                                                                 "MaxDataDiskCount" = $insideCapability.Value
                                                                 }
                            }
                        }
                    }
                }
            }
         }

$OutTable | select Name, MaxDataDiskCount | Sort-Object -Property Name | Format-Table

References: i. https://learn.microsoft.com/en-us/azure/azure-resource-manager/troubleshooting/error-sku-not-available?tabs=azure-powershell

ii. https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.commands.compute.automation.models.psresourcesku?view=az-ps-latest