Skip to content

Instantly share code, notes, and snippets.

@bmoore-msft
Last active January 14, 2021 16:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmoore-msft/126980ad876085106a4342db83b5c27b to your computer and use it in GitHub Desktop.
Save bmoore-msft/126980ad876085106a4342db83b5c27b to your computer and use it in GitHub Desktop.
Get the api versions and locations for a resource type published in the manifest
function api {
<#
.Synopsis
Get the api versions and locations for a resource type.
.Description
Lists all the available api versions and locations for a given resource type. Information is pulled from the /providers api
which returns the information in the manifest published to ARM.
.Notes
The resource parameter requires the format of Namespace/type, e.g. Microsoft.Storage/storageAccounts
> api Microsoft.Storage/storageAccounts
#>
param(
[Parameter(Mandatory = $true)][String]$resource
)
$a = $resource.Split('/', 2)
$ProviderNameSpace = $a[0]
$resourceTypeName = $a[1]
Write-Host $ProviderNameSpace
Write-Host $resourceTypeName
$resourceTypes = (Get-AzResourceProvider -ProviderNamespace $ProviderNameSpace).ResourceTypes
($resourceTypes | where-object { $_.ResourceTypeName -eq "$resourceTypeName" }).apiVersions
$v = ($resourceTypes | where-object { $_.ResourceTypeName -eq "$resourceTypeName" }).locations
$locations = @()
foreach($l in $v){
$locations += $l.replace(" ", "").toLower()
}
$locations | Sort-Object
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment