Setting the file. One moment.
Check Quota · Azure Quotas · microsoft/azure-skills · Skills Docs
ContentsBack to the top of the page (opens in a new tab)
scripts/ check-quota.ps1
PowerShell · 95 lines · 3 KB
13 Quota resource name (e.g., "standardDSv3Family"). If omitted, returns all quotas.
14 . PARAMETER SubscriptionId
15 Azure subscription ID. Defaults to the current subscription.
16 . EXAMPLE
17 .\check-quota.ps1 -ResourceProvider Microsoft.Compute -Region eastus
18 # Shows limit, usage, and available capacity for ALL compute quotas in eastus
19 . EXAMPLE
20 .\check-quota.ps1 -ResourceProvider Microsoft.Compute -Region eastus -ResourceName standardDSv3Family
21 # Shows limit, usage, and available capacity for the DSv3 VM family only
22 #>
23 param (
24 [ Parameter ( Mandatory )][ string ]$ResourceProvider ,
25 [ Parameter ( Mandatory )][ string ]$Region ,
26 [ string ]$ResourceName ,
27 [ string ]$SubscriptionId
28 )
29
30 $ErrorActionPreference = "Stop"
31
32 # Ensure the quota extension is installed
33 $ext = az extension list -- query "[?name=='quota'].name" - o tsv 2> $null
34 if ( -not $ext) {
35 Write-Host "Installing quota extension..."
36 az extension add -- name quota -- yes 2> $null
37 }
38
39 # Resolve subscription
40 if ( -not $SubscriptionId) {
41 $SubscriptionId = az account show -- query id - o tsv
42 }
43
44 $scope = "/subscriptions/ $SubscriptionId /providers/ $ResourceProvider /locations/ $Region "
45
46 Write-Host "Checking quotas in scope $scope "
47
48 if ($ResourceName) {
49 # Single-resource mode
50 Write-Host "Quota for ' $ResourceName ' ( $ResourceProvider , $Region ):"
51 Write-Host ""
52
53 $limit = az quota show -- resource - name $ResourceName -- scope $scope - o json 2> $null | ConvertFrom-Json
54 $usage = az quota usage show -- resource - name $ResourceName -- scope $scope - o json 2> $null | ConvertFrom-Json
55
56 $limitValue = $limit.properties.limit.value
57 $usageValue = $usage.properties.usages.value
58 $available = $limitValue - $usageValue
59
60 [ PSCustomObject ] @ {
61 Resource = $ResourceName
62 Region = $Region
63 Limit = $limitValue
64 Usage = $usageValue
65 Available = $available
66 } | Format-Table - AutoSize
67 } else {
68 # All-quotas mode: fetch limits and usage, join by name
69 Write-Host "Quotas for $ResourceProvider in ${Region} :"
70 Write-Host ""
71
72 $quotas = az quota list -- scope $scope - o json 2> $null | ConvertFrom-Json
73 $usages = az quota usage list -- scope $scope - o json 2> $null | ConvertFrom-Json
74
75 $usageLookup = @ {}
76 foreach ($u in $usages) {
77 $usageLookup[$u.name] = $u.properties.usages.value
78 }
79
80 $results = foreach ($q in $quotas) {
81 $name = $q.name
82 $limitValue = $q.properties.limit.value
83 $usageValue = if ($usageLookup.ContainsKey($name)) { $usageLookup[$name] } else { 0 }
84 $available = $limitValue - $usageValue
85 [ PSCustomObject ] @ {
86 Resource = $name
87 Region = $Region
88 Limit = $limitValue
89 Usage = $usageValue
90 Available = $available
91 }
92 }
93
94 $results | Format-Table - AutoSize
95 }