Last active
July 18, 2023 12:58
-
-
Save ljtill/334b86ffb2c720fb281309503632e8b3 to your computer and use it in GitHub Desktop.
Provides the ability to retrieve Resource Groups via REST API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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