When you are working with ARM templates you might want to quickly check the latest API version for different resources. This information is scattered across multiple help pages.
You can use the PowerShell command Get-AzureRmResourceProvider to get the latest API version for a particular resource. The below snippet gets the latest API version for the vaults resource type found under the Microsoft.KeyVault namespace.
$nameSpace = "Microsoft.KeyVault" $resourceType = "vaults" ((Get-AzureRmResourceProvider -ProviderNamespace $nameSpace).ResourceTypes | Where-Object ResourceTypeName -eq $resourceType).ApiVersions | Select-Object -First 1
The script below lets you export the Azure Resource Manager resource types, locations, and their API versions as a csv file. You probably have to do this periodically as new API versions are released frequently.
$fileName = ".\AzureRMResources.csv"
If (Test-Path $fileName){
Remove-Item $fileName
}
$providers = Get-AzureRmResourceProvider
Foreach($provider in $providers){
$provider.ResourceTypes | Select-Object @{Name = "Namespace"; Expression = {$provider.ProviderNamespace}},
@{Name = "ResourceTypeName"; Expression = {$_.ResourceTypeName}},
@{Name = "API Versions"; Expression = {($_.ApiVersions -join ", ")}},
@{Name = "Locations"; Expression = {($_.Locations -join ", ")}} |
Export-Csv $fileName -NoTypeInformation -Append
}
The script walks through each provider and its resource types, and writes the information to a csv file.