-
Notifications
You must be signed in to change notification settings - Fork 17
/
azure-az-available-skus.ps1
361 lines (301 loc) · 13.6 KB
/
azure-az-available-skus.ps1
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
<#
.SYNOPSIS
Get available virtual machine skus in a region
.DESCRIPTION
Get available skus in a region for a virtual machine.
Filter by location, sku name, max memory, max vcpu, computer architecture type, hyperVGenerations, withRestrictions, and serviceFabric.
If no skus are found, script returns $false to indicate no skus found else returns $true
Use the $filteredSkus variable to get details on available skus. example $filteredSkus | out-gridview
Can also be executed from https://shell.azure.com
.NOTES
File Name : azure-az-available-skus.ps1
Author : jagilber
Prerequisite : PowerShell core 6.1.0 or higher
version : 1.1
.PARAMETER force
Force refresh of skus
.PARAMETER hyperVGenerations
The hyperVGenerations to filter by
.PARAMETER maxMemoryGB
The maximum memory in GB to filter by
.PARAMETER maxVCPU
The maximum vcpu to filter by
.PARAMETER minMemoryGB
The minimum memory in GB to filter by
.PARAMETER minVCPU
The minimum vcpu to filter by
.PARAMETER location
The location to get available skus
.PARAMETER skuName
The sku name to filter by. regex based
.PARAMETER subscriptionId
The subscription id to use
.PARAMETER computerArchitectureType
The architecture type to filter by
.PARAMETER withRestrictions
Include skus with restrictions
.PARAMETER serviceFabric
Filter for service fabric skus
.EXAMPLE
.\azure-az-available-skus.ps1 -location "eastus" -serviceFabric
Get available skus in eastus for service fabric clusters
.EXAMPLE
.\azure-az-available-skus.ps1 -skuName 'Standard_D2'
Get available skus in all regions with sku name regex matching Standard_D2
.EXAMPLE
.\azure-az-available-skus.ps1 -maxMemoryGB 64 -maxVCPU 12
Get available skus in all regions with memory <= 64GB and vcpu <= 12
.EXAMPLE
.\azure-az-available-skus.ps1 -maxMemoryGB 64 -maxVCPU 12 -location "eastus"
Get available skus in all regions with memory <= 64GB and vcpu <= 12 in eastus
.EXAMPLE
.\azure-az-available-skus.ps1 -maxMemoryGB 64 -maxVCPU 12 -hyperVGenerations "V1,V2"
Get available skus in all regions with memory <= 64GB and vcpu <= 12 for hyperVGenerations V1 or V2 (V1 is default and required for sf)
.EXAMPLE
.\azure-az-available-skus.ps1 -Location "eastus" -computerArchitectureType "x64"
Get available skus in eastus for x64 architecture
.EXAMPLE
.\azure-az-available-skus.ps1 -Location "eastus" -computerArchitectureType "x64" -verbose
Get available skus in eastus for x64 architecture with verbose output
.EXAMPLE
.\azure-az-available-skus.ps1 -Location "eastus" -computerArchitectureType "x64" -withRestrictions
Get available skus in eastus for x64 architecture including skus with restrictions
.EXAMPLE
.\azure-az-available-skus.ps1 -Location "eastus" -computerArchitectureType "ARM64" -withRestrictions
Get available skus in eastus for ARM64 architecture including skus with restrictions
.OUTPUTS
[bool] $true if skus are found, $false if no skus are found
.LINK
[net.servicePointManager]::Expect100Continue = $true;[net.servicePointManager]::SecurityProtocol = [net.SecurityProtocolType]::Tls12;
invoke-webRequest "https://raw.githubusercontent.com/jagilber/powershellScripts/master/azure-az-available-skus.ps1" -outFile "$pwd\azure-az-available-skus.ps1";
.\azure-az-available-skus.ps1
#>
[cmdletbinding()]
param (
[string]$location = $null,
[string]$subscriptionId = $null,
[string]$computerArchitectureType = "x64",
[ValidateSet("V1", "V2", "V1,V2", "", ".")]
[string]$hyperVGenerations = ".",
[string]$skuName = $null,
[int]$maxMemoryGB = 0, # 64, # 0 = unlimited
[int]$maxVCPU = 0, # 4, # 0 = unlimited
[int]$minMemoryGB = 0, # 0 = unlimited
[int]$minVCPU = 0, # 0 = unlimited
[switch]$withRestrictions,
[switch]$serviceFabric, # hyperVGenerations needs "V1" or "V1,V2" for sf
[switch]$force
)
$global:filteredSkus = @{}
function main() {
try {
if (!(connect-az)) { return }
if ($serviceFabric) {
$computerArchitectureType = "x64"
$hyperVGenerations = "V1"
}
if (!$global:locations -or $force) {
write-host "Get-AzLocation | Where-Object Providers -imatch 'Microsoft.Compute'" -ForegroundColor Cyan
$global:locations = get-azlocation | where-object Providers -imatch 'Microsoft.Compute'
if (!$global:locations) {
write-error "no locations found"
return
}
}
if ($location -and ($global:locations.location -inotcontains $location)) {
write-host ($locations | out-string) -ForegroundColor Cyan
write-error "location $location is not valid"
return
}
if (!$global:skus -or $force) {
$global:skus = @{}
write-host "retrieving skus" -ForegroundColor Green
write-host "Get-AzComputeResourceSku | Where-Object { `$psitem.resourceType -ieq 'virtualMachines' }" -ForegroundColor Cyan
$global:skus = Get-AzComputeResourceSku | Where-Object {
$psitem.resourceType -ieq 'virtualMachines' `
-and $global:locations.Location -icontains $psitem.LocationInfo.Location
}
write-host "global:skus:$($global:skus.Count)" -ForegroundColor Cyan
}
if ($location) {
write-host "filtering skus by location $location" -ForegroundColor Green
write-host "
`$global:filteredSkus = `$global:skus | Where-Object {
`$psitem.Locations -ieq $location
}" -ForegroundColor Cyan
$global:filteredSkus = $global:skus | Where-Object {
$psitem.Locations -ieq $location
}
write-verbose "available skus:`n$($global:skus | convertto-json -depth 10)"
write-host "filtered skus ($($global:filteredSkus.Count))" -ForegroundColor Green
}
else {
$global:filteredSkus = $global:skus
}
if (!$global:skus) {
write-error "no skus found in region $location"
return
}
write-host "`$global:filteredSkus = `$global:skus" -ForegroundColor Cyan
if (!$withRestrictions) {
write-host "`$global:filteredSkus = `$global:filteredSkus | Where-Object { `$psitem.Restrictions.Count -eq 0 }" -ForegroundColor Cyan
$global:filteredSkus = $global:filteredSkus | Where-Object { $psitem.Restrictions.Count -eq 0 }
write-verbose "unrestricted skus in region:`n$($global:filteredSkus | convertto-json -depth 10)"
write-host "unrestricted skus in region ($($global:filteredSkus.Count))" -ForegroundColor Green
}
if ($skuName) {
write-host "`$global:filteredSkus = `$global:filteredSkus | Where-Object { `$psitem.Name -imatch $skuName }" -ForegroundColor Cyan
$global:filteredSkus = $global:filteredSkus | Where-Object { $psitem.Name -imatch $skuName }
write-verbose "skus in region:`n$($global:filteredSkus | convertto-json -depth 10)"
write-host "skus in region ($($global:filteredSkus.Count))" -ForegroundColor Green
}
if ($computerArchitectureType) {
write-host "filtering skus by Capabilities.CpuArchitectureType = '$computerArchitectureType'" -ForegroundColor Green
write-host "
`$global:filteredSkus = `$global:filteredSkus | Where-Object {
`$psitem.Capabilities | where-object {
`$psitem.Name -ieq 'CpuArchitectureType' -and `$psitem.Value -ieq $computerArchitectureType
}" -ForegroundColor Cyan
$global:filteredSkus = $global:filteredSkus | Where-Object {
$psitem.Capabilities | where-object {
$psitem.Name -ieq 'CpuArchitectureType' -and $psitem.Value -ieq $computerArchitectureType
}
}
write-verbose "filtered skus:`n$($global:filteredSkus | convertto-json -depth 10)"
write-host "filtered skus ($($global:filteredSkus.Count))" -ForegroundColor Green
}
if ($hyperVGenerations) {
write-host "filtering skus by Capabilities.HyperVGenerations = '$hyperVGenerations'" -ForegroundColor Green
write-host "
`$global:filteredSkus = `$global:filteredSkus | Where-Object {
`$psitem.Capabilities | where-object {
`$psitem.Name -ieq 'HyperVGenerations' -and `$psitem.Value -imatch $hyperVGenerations
}" -ForegroundColor Cyan
$global:filteredSkus = $global:filteredSkus | Where-Object {
$psitem.Capabilities | where-object {
$psitem.Name -ieq 'HyperVGenerations' -and $psitem.Value -imatch $hyperVGenerations
}
}
write-verbose "filtered skus:`n$($global:filteredSkus | convertto-json -depth 10)"
write-host "filtered skus ($($global:filteredSkus.Count))" -ForegroundColor Green
}
if ($maxMemoryGB) {
write-host "filtering skus by Capabilities.MemoryGB <= $maxMemoryGB" -ForegroundColor Green
write-host "
`$global:filteredSkus = `$global:filteredSkus | Where-Object {
`$psitem.Capabilities | where-object {
`$psitem.Name -ieq 'MemoryGB' -and [int]`$psitem.Value -le $maxMemoryGB
}
}" -ForegroundColor Cyan
$global:filteredSkus = $global:filteredSkus | where-object {
$psitem.Capabilities | where-object {
$psitem.Name -ieq 'MemoryGB' -and [int]$psitem.Value -le $maxMemoryGB
}
}
write-verbose "filtered skus:`n$($global:filteredSkus | convertto-json -depth 10)"
write-host "filtered skus ($($global:filteredSkus.Count))" -ForegroundColor Green
}
if ($maxVCPU) {
write-host "filtering skus by Capabilities.VCPUs <= $maxVCPU" -ForegroundColor Green
write-host "
`$global:filteredSkus = `$global:filteredSkus | Where-Object {
`$psitem.Capabilities | where-object {
`$psitem.Name -ieq 'VCPUs' -and [int]`$psitem.Value -le $maxVCPU
}
}" -foregroundColor Cyan
$global:filteredSkus = $global:filteredSkus | where-object {
$psitem.Capabilities | where-object {
$psitem.Name -ieq 'VCPUs' -and [int]$psitem.Value -le $maxVCPU
}
}
write-verbose "filtered skus:`n$($global:filteredSkus | convertto-json -depth 10)"
write-host "filtered skus ($($global:filteredSkus.Count))" -ForegroundColor Green
}
if ($minMemoryGB) {
write-host "filtering skus by Capabilities.MemoryGB >= $minMemoryGB" -ForegroundColor Green
write-host "
`$global:filteredSkus = `$global:filteredSkus | Where-Object {
`$psitem.Capabilities | where-object {
`$psitem.Name -ieq 'MemoryGB' -and [int]`$psitem.Value -ge $minMemoryGB
}
}" -ForegroundColor Cyan
$global:filteredSkus = $global:filteredSkus | where-object {
$psitem.Capabilities | where-object {
$psitem.Name -ieq 'MemoryGB' -and [int]$psitem.Value -ge $minMemoryGB
}
}
write-verbose "filtered skus:`n$($global:filteredSkus | convertto-json -depth 10)"
write-host "filtered skus ($($global:filteredSkus.Count))" -ForegroundColor Green
}
if ($minVCPU) {
write-host "filtering skus by Capabilities.VCPUs >= $minVCPU" -ForegroundColor Green
write-host "
`$global:filteredSkus = `$global:filteredSkus | Where-Object {
`$psitem.Capabilities | where-object {
`$psitem.Name -ieq 'VCPUs' -and [int]`$psitem.Value -ge $minVCPU
}
}" -foregroundColor Cyan
$global:filteredSkus = $global:filteredSkus | where-object {
$psitem.Capabilities | where-object {
$psitem.Name -ieq 'VCPUs' -and [int]$psitem.Value -ge $minVCPU
}
}
write-verbose "filtered skus:`n$($global:filteredSkus | convertto-json -depth 10)"
write-host "filtered skus ($($global:filteredSkus.Count))" -ForegroundColor Green
}
write-verbose "filtered skus:`n$($global:filteredSkus | convertto-json -depth 10)"
write-host "filtered skus ($($global:filteredSkus.Count)):`n$($global:filteredSkus | sort-object | out-string)" -ForegroundColor Magenta
$locationGroup = $filteredSkus.LocationInfo.Location | group-object
if ($locationGroup.Count -gt 1) {
write-host "sku types grouped by location:`n$($locationGroup | select-object Count,Name | sort-object Name | out-string)" -ForegroundColor DarkMagenta
}
write-host "filtered skus with:
location: $location
computerArchitectureType: $computerArchitectureType
hyperVGenerations: $hyperVGenerations
maxMemoryGB: $maxMemoryGB
maxVCPU: $maxVCPU
skuName: $skuName
withRestrictions: $withRestrictions
" -ForegroundColor DarkGray
write-host "use variable `$filteredSkus to get details on available skus. example `$filteredSkus | out-gridview" -ForegroundColor Green
return ($filteredSkus.Count -gt 0)
}
catch {
write-verbose "variables:$((get-variable -scope local).value | convertto-json -WarningAction SilentlyContinue -depth 2)"
write-host "exception::$($psitem.Exception.Message)`r`n$($psitem.scriptStackTrace)" -ForegroundColor Red
return $false
}
finally {
}
}
function connect-az($subscriptionId) {
$moduleList = @('az.accounts', 'az.resources', 'az.compute')
foreach ($module in $moduleList) {
write-verbose "checking module $module"
if (!(get-module -name $module)) {
if (!(get-module -name $module -listavailable)) {
write-host "installing module $module" -ForegroundColor Yellow
install-module $module -force
import-module $module
if (!(get-module -name $module -listavailable)) {
return $false
}
}
}
}
if ($subscriptionId -and (Get-AzContext).Subscription.Id -ne $subscriptionId) {
write-host "setting subscription $subscriptionId" -ForegroundColor Yellow
set-azcontext -SubscriptionId $subscriptionId
}
if (!(@(Get-AzResourceGroup).Count)) {
$error.clear()
Connect-AzAccount
if ($error -and ($error | out-string) -match '0x8007007E') {
$error.Clear()
Connect-AzAccount -UseDeviceAuthentication
}
}
return $null = get-azcontext
}
main