MantyQuestions
MantyQuestions

Reputation: 379

Check if azure VM compute Quota is available for a VM size via powershell

I am looking to see if there is a way to check my current azure quota based on input of a VM size? (NOT a VM family)

Sample input:

Standard_D1

Sample output:

Standard DDSv4 Family vCPUs: You have used X/Y available quota

Upvotes: 1

Views: 1444

Answers (1)

Bhargavi Annadevara
Bhargavi Annadevara

Reputation: 5502

The closest you can get to doing that is through the Usage - List API that @Jim mentioned above. The same is exposed via the Get-AzVMUsage PS cmdlet as well. Note that this cmdlet can only accept a Location parameter and not a VM Size as such.

Get-AzVMUsage -Location "West US 2"

However, if there is a hard requirement for you to fetch the quota for the size you provide, you could combine it with Get-AzComputeResourceSku as follows:

$Location = 'West US 2'
$VMSize = 'Standard_D4d_v4'

# Get the list of VM SKUs for the given location
$SKU = Get-AzComputeResourceSku -Location $Location | where ResourceType -eq "virtualMachines" | select Name,Family

# Figure out the VM Family for the provided size
$VMFamily = ($SKU | where Name -eq $VMSize | select -Property Family).Family

# Fetch the usage
$Usage = Get-AzVMUsage -Location $Location | Where-Object { $_.Name.Value -eq $VMFamily }

Write-Output "$($Usage.Name.LocalizedValue): You have consumed $($Usage.CurrentValue)/$($Usage.Limit) available quota"

# Sample Output
# Standard DDv4 Family vCPUs: You have consumed 16/100 available quota

Also take a look at this article for more information about vCPU quotas.

Upvotes: 2

Related Questions