Skip to content

Instantly share code, notes, and snippets.

@martin77s
Last active April 8, 2019 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martin77s/bdf9f93edf4bf06b2730e5c2fbfa8eb0 to your computer and use it in GitHub Desktop.
Save martin77s/bdf9f93edf4bf06b2730e5c2fbfa8eb0 to your computer and use it in GitHub Desktop.
Get the VM sizes available by location (region)
function Get-AzVmSizesByLocation {
[CmdletBinding()]
param($LocationFilter = '*')
Write-Verbose -Message 'Getting all locations with the vmSizes providers'
$locations = Get-AzResourceProvider |
Where-Object { $_.ResourceTypes.ResourceTypeName -contains 'locations/vmSizes' } |
Select-Object -ExpandProperty Locations
Write-Verbose -Message 'Filtering in the specified locations'
$filteredLocations = $locations | Where-Object {
$location = $_
$LocationFilter | Where-Object { $location -like $_ }
}
Write-Verbose -Message 'Getting all the sizes, and adding the Location property'
$sizes = $filteredLocations | ForEach-Object {
$location = $_
Get-AzVMSize -Location $location | Select-Object Name, NumberOfCores, MemoryInMB,
OSDiskSizeInMB, ResourceDiskSizeInMB, MaxDataDiskCount, @{N='Location';E={$location}}
}
$sizes
}
# Usage examples:
$vmSizes = Get-AzVmSizesByLocation
$vmSizes = Get-AzVmSizesByLocation -LocationFilter '*Europe*'
$vmSizes = Get-AzVmSizesByLocation -LocationFilter @('*Africa*', 'West US*')
# Optional: Save the output to file (or show in datagrid)
$vmSizes | Export-Csv -NoTypeInformation -Path C:\Temp\VMSizes.csv
$vmSizes | Out-GridView
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment