Skip to content

Instantly share code, notes, and snippets.

@ljtill
Last active July 18, 2023 12:59
Show Gist options
  • Select an option

  • Save ljtill/787643e07810a4cac534e58b96ea2607 to your computer and use it in GitHub Desktop.

Select an option

Save ljtill/787643e07810a4cac534e58b96ea2607 to your computer and use it in GitHub Desktop.
Provides the ability to retrieve API version of a Resource Provider
function Get-AzureRmApiVersion {
<#
.SYNOPSIS
Get-AzureRmApiVersion returns the api versions of Resource Providers.
.DESCRIPTION
Provides the ability to retrieve all api versions or the latest api version of a specific Resource Provider.
.EXAMPLE
Get-AzureRmApiVersion -SubscriptionId $subscriptionId -Namespace "" -ResourceType "" -AccessToken $accessToken
.LINK
https://gist.github.com/ljtill
#>
[CmdletBinding()]
param (
[Parameter()]
[string]$SubscriptionId,
[Parameter()]
[string]$Namespace,
[Parameter()]
[string]$ResourceType,
[Parameter()]
[switch]$Latest,
[Parameter()]
[string]$AccessToken
)
begin {
$apiVersion = "2018-02-01"
$request = @{
Method = "GET"
Uri = ("https://management.azure.com/subscriptions/" + $subscriptionId + "/providers?api-version=" + $apiVersion)
Headers = @{
"Authorization" = ("Bearer " + $accessToken)
"Accept" = "application/json"
}
Body = $null
}
}
process {
$response = Invoke-RestMethod @request
$response.value | ForEach-Object {
if ($_.namespace -eq $namespace) {
$_.resourceTypes | ForEach-Object {
if ($_.resourceType -eq $resourceType) {
if ($latest) {
$output = ($_.apiVersions)[0]
} else {
$output = $_.apiVersions
}
}
}
}
}
}
end {
return $output
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment