Created
March 19, 2020 12:17
-
-
Save krnese/5153f7ce8dd0fe746d59701928a82d6f to your computer and use it in GitHub Desktop.
List Mg hiearchy
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-AzMgHierarchy { | |
[cmdletbinding()] | |
param ( | |
[string]$mgGroupId | |
) | |
# Getting Azure connection context for the signed in user | |
$currentContext = Get-AzContext | |
# fetching new token | |
$azureRmProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile | |
$profileClient = [Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient]::new($azureRmProfile) | |
$token = $profileClient.AcquireAccessToken($currentContext.Subscription.TenantId) | |
# Listing All Subscriptions to grab their tenantId's | |
$listDescendants = @{ | |
Uri = "https://management.azure.com/providers/Microsoft.Management/managementGroups/$($mgGroupId)/descendants?api-version=2018-03-01-preview" | |
Headers = @{ | |
Authorization = "Bearer $($token.AccessToken)" | |
'Content-Type' = 'application/json' | |
} | |
Method = 'GET' | |
} | |
$list = Invoke-RestMethod @listDescendants | |
$list.value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment