-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathGetVmSkus.ps1
More file actions
85 lines (75 loc) · 2.77 KB
/
GetVmSkus.ps1
File metadata and controls
85 lines (75 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
[CmdletBinding()]
param()
# Adjust to test your regions
$regions = @("GermanyWestcentral", "italynorth")
$nameLike = "Standard_D[24]s_v*"
$all = foreach ($region in $regions) {
$regionalVcpuAvailable = $null
try {
$usage = Get-AzVMUsage -Location $region
$totalRegional = $usage | Where-Object {
($_.Name.Value -match 'Total\s*Regional\s*(vCPUs|Cores)') -or
($_.Name.LocalizedValue -match 'Total\s*Regional\s*(vCPUs|Cores)')
} | Select-Object -First 1
if (-not $totalRegional) {
$totalRegional = $usage | Where-Object {
($_.Name.Value -match 'Regional\s*(vCPUs|Cores)') -or
($_.Name.LocalizedValue -match 'Regional\s*(vCPUs|Cores)')
} | Sort-Object Limit -Descending | Select-Object -First 1
}
if ($totalRegional) {
$regionalVcpuAvailable = [int64]$totalRegional.Limit - [int64]$totalRegional.CurrentValue
}
} catch {}
$skus = @()
try {
$skus = Get-AzComputeResourceSku -Location $region |
Where-Object {
$_.ResourceType -eq "virtualMachines" -and
$_.Locations -contains $region -and
$_.Name -like $nameLike -and
(($_.Capabilities | Where-Object Name -eq "HyperVGenerations").Value -match "V1")
}
} catch {}
foreach ($sku in $skus) {
$cap = @{}
foreach ($c in $sku.Capabilities) { $cap[$c.Name] = $c.Value }
$rwe = @()
if ($sku.Restrictions) {
$rwe = $sku.Restrictions | Where-Object {
($_.RestrictionInfo -and ($_.RestrictionInfo.Locations -contains $region)) -or
($_.Locations -and $_.Locations -contains $region)
}
}
if (-not $rwe -or $rwe.Count -eq 0) {
[pscustomobject]@{
Scope = $region
Name = $sku.Name
vCPUs = $cap['vCPUs']
MemoryGB = $cap['MemoryGB']
HyperVGenerations = $cap['HyperVGenerations']
RegionalVcpuAvailable = $regionalVcpuAvailable
RestrictionType = 'None'
ReasonCode = ''
Zones = ''
}
} else {
foreach ($r in $rwe) {
$zones = 'AllZones/NotSpecified'
if ($r.RestrictionInfo -and $r.RestrictionInfo.Zones) { $zones = ($r.RestrictionInfo.Zones -join ',') }
[pscustomobject]@{
Scope = $region
Name = $sku.Name
vCPUs = $cap['vCPUs']
MemoryGB = $cap['MemoryGB']
HyperVGenerations = $cap['HyperVGenerations']
RegionalVcpuAvailable = $regionalVcpuAvailable
RestrictionType = $r.Type
ReasonCode = $r.ReasonCode
Zones = $zones
}
}
}
}
}
$all | Sort-Object Scope, Name, RestrictionType | Format-Table -Auto