Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Check and manage Azure subscription quotas, usage limits, and request capacity increases
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
scripts/check-quota.ps1
1<#2.SYNOPSIS3Checks Azure quota limits and current usage for a resource provider.4.DESCRIPTION5Installs the quota CLI extension if needed, then queries quota limits and6current usage in a single call. Returns a table with limit, usage, and7available capacity for every quota (or a single quota when ResourceName is provided).8.PARAMETER ResourceProvider9Azure resource provider namespace (e.g., "Microsoft.Compute", "Microsoft.Network").10.PARAMETER Region11Azure region to check (e.g., "eastus", "westus2").12.PARAMETER ResourceName13Quota resource name (e.g., "standardDSv3Family"). If omitted, returns all quotas.14.PARAMETER SubscriptionId15Azure subscription ID. Defaults to the current subscription.16.EXAMPLE17.\check-quota.ps1 -ResourceProvider Microsoft.Compute -Region eastus18# Shows limit, usage, and available capacity for ALL compute quotas in eastus19.EXAMPLE20.\check-quota.ps1 -ResourceProvider Microsoft.Compute -Region eastus -ResourceName standardDSv3Family21# Shows limit, usage, and available capacity for the DSv3 VM family only22#>23param(24[Parameter(Mandatory)][string]$ResourceProvider,25[Parameter(Mandatory)][string]$Region,26[string]$ResourceName,27[string]$SubscriptionId28)2930$ErrorActionPreference = "Stop"3132# Ensure the quota extension is installed33$ext = az extension list --query "[?name=='quota'].name" -o tsv 2>$null34if (-not $ext) {35Write-Host "Installing quota extension..."36az extension add --name quota --yes 2>$null37}3839# Resolve subscription40if (-not $SubscriptionId) {41$SubscriptionId = az account show --query id -o tsv42}4344$scope = "/subscriptions/$SubscriptionId/providers/$ResourceProvider/locations/$Region"4546Write-Host "Checking quotas in scope $scope"4748if ($ResourceName) {49# Single-resource mode50Write-Host "Quota for '$ResourceName' ($ResourceProvider, $Region):"51Write-Host ""5253$limit = az quota show --resource-name $ResourceName --scope $scope -o json 2>$null | ConvertFrom-Json54$usage = az quota usage show --resource-name $ResourceName --scope $scope -o json 2>$null | ConvertFrom-Json5556$limitValue = $limit.properties.limit.value57$usageValue = $usage.properties.usages.value58$available = $limitValue - $usageValue5960[PSCustomObject]@{61Resource = $ResourceName62Region = $Region63Limit = $limitValue64Usage = $usageValue65Available = $available66} | Format-Table -AutoSize67} else {68# All-quotas mode: fetch limits and usage, join by name69Write-Host "Quotas for $ResourceProvider in ${Region}:"70Write-Host ""7172$quotas = az quota list --scope $scope -o json 2>$null | ConvertFrom-Json73$usages = az quota usage list --scope $scope -o json 2>$null | ConvertFrom-Json7475$usageLookup = @{}76foreach ($u in $usages) {77$usageLookup[$u.name] = $u.properties.usages.value78}7980$results = foreach ($q in $quotas) {81$name = $q.name82$limitValue = $q.properties.limit.value83$usageValue = if ($usageLookup.ContainsKey($name)) { $usageLookup[$name] } else { 0 }84$available = $limitValue - $usageValue85[PSCustomObject]@{86Resource = $name87Region = $Region88Limit = $limitValue89Usage = $usageValue90Available = $available91}92}9394$results | Format-Table -AutoSize95}96