-
-
Save ehrnst/2e4fdcb4154e4ce83ba1cd595e6ba8c8 to your computer and use it in GitHub Desktop.
Azure REST Get all resource groups
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
#Loop through each reasource group and get all resources. | |
#Add everything to a hash table | |
$Groups = @() | |
foreach ($rg in $ResourceGroups) { | |
$ResourceGroupUri = "https://management.azure.com/subscriptions/$subscriptionID/resourceGroups/$rg/resources?api-version=$APIVersion" | |
$res = (Invoke-RestMethod -Uri $ResourceGroupUri -Method GET -Headers $authHeader).value | |
#Create array of all resources | |
$resources = @{} | |
$resources.Add($rg, $res) | |
#Add all resource groups and their resources to a hash table | |
$Groups += $resources | |
} |
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
#get all resource groups within a subscription | |
$APIVersion = "2017-05-10" | |
$subscriptionID = "xxxxxxxxxxxx-xxx-xxx-xxxxxxxxxx" | |
$RGURI = "https://management.azure.com/subscriptions/$subscriptionID/resourcegroups?api-version=$APIVersion" | |
$ResourceGroups = (Invoke-RestMethod -Uri $RGuri -Method GET -Headers $authHeader).value.name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment