Skip to content

Instantly share code, notes, and snippets.

@ljtill
Last active July 18, 2023 12:58
Show Gist options
  • Save ljtill/334b86ffb2c720fb281309503632e8b3 to your computer and use it in GitHub Desktop.
Save ljtill/334b86ffb2c720fb281309503632e8b3 to your computer and use it in GitHub Desktop.
Provides the ability to retrieve Resource Groups via REST API
function Get-AzureRmResourceGroups {
<#
.SYNOPSIS
Get-AzureRmResourceGroups will retrieve all Resource Groups within a Subscription.
.DESCRIPTION
Provides the ability to retrieve all Resource Groups from a specific Subscription Id via REST API.
.EXAMPLE
Get-AzureRmResourceGroups -SubscriptionId $subscriptionId -AccessToken $accessToken.
.LINK
https://gist.github.com/ljtill
#>
[CmdletBinding()]
param (
[Parameter()]
[string]$SubscriptionId,
[Parameter()]
[string]$AccessToken
)
begin {
$apiVersion = "2018-02-01"
$request = @{
Method = "GET"
Uri = ("https://management.azure.com/subscriptions/" + $subscriptionId + "/resourcegroups?api-version=" + $apiVersion)
Headers = @{
"Authorization" = ("Bearer " + $accessToken)
"Accept" = "application/json"
}
Body = $null
}
}
process {
$response = Invoke-RestMethod @request
}
end {
return $response.value
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment