-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathazure-az-available-skus.ps1
538 lines (461 loc) · 20.1 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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
<#
.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 and MaxResourceVolumeMB needs temp disk (10000) 10gb and vmDeploymentTypes needs "PaaS"
[ValidateSet("paas", "iaas", "")]
[int]$maxResourceVolumeMB = -1, # 0 is no local disk -1 is unlimited
[int]$minResourceVolumeMB = -1, # 0 is no local disk -1 is minimum (1)
[string]$vmDeploymentTypes = "",
[switch]$confidentialComputingType,
[switch]$force
)
$global:filteredSkus = @{}
$global:regions = @($location.Split(','))
function main() {
try {
if (!(connect-az)) { return }
if ($serviceFabric) {
$computerArchitectureType = "x64"
$hyperVGenerations = "V1"
$minResourceVolumeMB = 10000
$vmDeploymentTypes = "PaaS"
$confidentialComputingType = $false
}
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' }
write-host "global:skus:$($global:skus.Count)" -ForegroundColor Cyan
}
$global:filteredSkus = $global:skus
write-host "`$global:filteredSkus = `$global:skus" -ForegroundColor Cyan
check-withRestrictions
check-skuName
check-computerArchitectureType
check-hyperVGenerations
check-resourceVolumeMB # check local storage
check-maxvCpu
check-minvCpu
check-maxMemoryGB
check-minMemoryGB
check-vmDeploymentTypes # checking for no gpu on sf
check-confidentialComputingType
if (!$global:filteredSkus) {
write-warning "no skus found"
return $false
}
$skus = check-location $global:regions $global:filteredSkus
if (!$skus) {
$regions = check-geoRegion $global:regions
$skus = check-location $regions $global:filteredSkus
if (!$skus) {
write-warning "no skus found in georegion $location"
}
}
if ($skus) {
$global:filteredSkus = $skus
}
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
MaxResourceVolumeMB: $maxResourceVolumeMB
vmDeploymentTypes: $vmDeploymentTypes
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-host "exception::$($psitem.Exception.Message)`r`n$($psitem.scriptStackTrace)" -ForegroundColor Red
write-verbose "variables:$((get-variable -scope local).value | convertto-json -WarningAction SilentlyContinue -depth 2)"
return $false
}
finally {
}
}
function check-computerArchitectureType() {
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
}
}
function check-confidentialComputingType() {
if ($confidentialComputingType) {
write-host "filtering skus by Capabilities.ConfidentialComputingType = '$confidentialComputingType'" -ForegroundColor Green
write-host "
`$global:filteredSkus = `$global:filteredSkus | Where-Object {
`$psitem.Capabilities | where-object {
`$psitem.Name -ieq 'ConfidentialComputingType' -and `$psitem.Value -imatch $confidentialComputingType
}" -ForegroundColor Cyan
$global:filteredSkus = $global:filteredSkus | Where-Object {
$psitem.Capabilities | where-object {
$psitem.Name -ieq 'ConfidentialComputingType' -and $psitem.Value -imatch $confidentialComputingType
}
}
write-verbose "filtered skus:`n$($global:filteredSkus | convertto-json -depth 10)"
write-host "filtered skus ($($global:filteredSkus.Count))" -ForegroundColor Green
}
else {
write-host "removing skus by Capabilities.ConfidentialComputingType != `$null" -ForegroundColor Green
write-host "
`$tempSkus = [collections.arrayList]::new(`$global:filteredSkus)
`$global:filteredSkus | Where-Object {
`$sku = $psitem
foreach (`$capability in `$sku.Capabilities) {
if (`$capability.Name -ieq 'ConfidentialComputingType') {
[void]`$tempSkus.Remove(`$sku)
return
}
}
}" -ForegroundColor Cyan
$tempSkus = [collections.arrayList]::new(@($global:filteredSkus))
$global:filteredSkus | Where-Object {
$sku = $psitem
foreach ($capability in $sku.Capabilities) {
if ($capability.Name -ieq 'ConfidentialComputingType') {
#write-host "removing sku $($capability.Name) with value $($capability.Value)" -ForegroundColor Yellow
[void]$tempSkus.Remove($sku)
#write-host "temp skus count: ($($tempSkus.Count))" -ForegroundColor Magenta
return
}
}
}
$global:filteredSkus = $tempSkus.ToArray()
write-verbose "filtered skus:`n$($global:filteredSkus | convertto-json -depth 10)"
write-host "filtered skus ($($global:filteredSkus.Count))" -ForegroundColor Green
}
}
function check-geoRegion([string[]]$regions) {
if (!$regions) { return $null }
$geoGroups = $global:locations.GeographyGroup | select-object -Unique
$geoGroups = ($global:locations | where-object Location -in $regions | select-object GeographyGroup).GeographyGroup
write-host "searching for regions in geoGroup: $geoGroups" -ForegroundColor Cyan
$geoRegions = @($global:locations | where-object GeographyGroup -in $geoGroups).location | sort-object
write-host "regions in geoGroup:`n$($geoRegions | out-string)" -ForegroundColor Cyan
write-host "returning regions for: $($geoGroups | out-string)"
return $geoRegions
}
function check-hyperVGenerations() {
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
}
}
function check-location([string[]]$locations, [object[]]$skus) {
if ($locations.Length -gt 0) {
write-host "filtering skus by locations $locations" -ForegroundColor Green
write-host "
`$skus = `$skus | Where-Object {
`$psitem.Locations -in $locations
}" -ForegroundColor Cyan
$skus = $skus | Where-Object {
$psitem.Locations -in $locations
}
write-verbose "available skus:`n$($skus | convertto-json -depth 10)"
}
else {
# $global:filteredSkus = $global:skus
write-host "no location specified. returning all skus" -ForegroundColor Yellow
}
write-host "filtered skus ($($skus.Count))" -ForegroundColor Green
return $skus
}
function check-locations([string[]]$locations) {
$geoRegions = check-geoRegion $locations
if ($geoRegions) {
$global:filteredSkus = @($global:skus | where-object Locations -in $geoRegions)
write-host "skus found in geo regions $(convertto-json $geoRegions)" -ForegroundColor Green
}
else {
write-error "no skus found in geo region $location"
return $false
}
if (!$global:filteredSkus) {
write-error "no skus found in region $location"
return $false
}
return $true
}
function check-maxMemoryGB() {
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
}
}
function check-maxvCpu() {
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
}
}
function check-minMemoryGB() {
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
}
}
function check-minvCpu() {
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
}
}
function check-resourceVolumeMB() {
if ($maxResourceVolumeMB -ne -1 -or $minResourceVolumeMB -ne -1) {
if ($maxResourceVolumeMB -eq -1) { $maxResourceVolumeMB = [int]::MaxValue }
if ($minResourceVolumeMB -eq -1) { $minResourceVolumeMB = 1 }
write-host "checking for local storage" -ForegroundColor Green
write-host "filtering skus by Capabilities.MaxResourceVolumeMB <= '$maxResourceVolumeMB' and Capabilities.MaxResourceVolumeMB >= $minResourceVolumeMB" -ForegroundColor Green
write-host "
`$global:filteredSkus = `$global:filteredSkus | Where-Object {
`$psitem.Capabilities | where-object {
`$psitem.Name -ieq 'MaxResourceVolumeMB' -and (`$psitem.Value -le $maxResourceVolumeMB -and `$psitem.Value -ge $minResourceVolumeMB)
}" -ForegroundColor Cyan
$global:filteredSkus = $global:filteredSkus | Where-Object {
$psitem.Capabilities | where-object {
$psitem.Name -ieq 'MaxResourceVolumeMB' -and ($psitem.Value -le $maxResourceVolumeMB -and $psitem.Value -ge $minResourceVolumeMB)
}
}
write-verbose "filtered skus:`n$($global:filteredSkus | convertto-json -depth 10)"
write-host "filtered skus ($($global:filteredSkus.Count))" -ForegroundColor Green
}
}
function check-skuName() {
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
}
}
function check-vmDeploymentTypes() {
if ($vmDeploymentTypes) {
write-host "filtering skus by Capabilities.VMDeploymentTypes = '$vmDeploymentTypes'" -ForegroundColor Green
write-host "
`$global:filteredSkus = `$global:filteredSkus | Where-Object {
`$psitem.Capabilities | where-object {
`$psitem.Name -ieq 'VMDeploymentTypes' -and `$psitem.Value -imatch $vmDeploymentTypes
}" -ForegroundColor Cyan
$global:filteredSkus = $global:filteredSkus | Where-Object {
$psitem.Capabilities | where-object {
$psitem.Name -ieq 'VMDeploymentTypes' -and $psitem.Value -imatch $vmDeploymentTypes
}
}
write-verbose "filtered skus:`n$($global:filteredSkus | convertto-json -depth 10)"
write-host "filtered skus ($($global:filteredSkus.Count))" -ForegroundColor Green
}
}
function check-withRestrictions() {
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
}
}
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