All scripts
Azure AI 925

Get-AzureManagementGroupInventory

Maps the full management group hierarchy along with subscriptions under each node, so the actual structure can be verified against what governance policy assumes it looks like.

Get-AzureManagementGroupInventory.ps1
<#
.SYNOPSIS
    Maps the management group hierarchy and subscription placement.

.DESCRIPTION
    Walks the management group tree recursively and lists every
    subscription's placement within it, so the actual structure can be
    verified against what governance policy assumes it looks like,
    rather than trusting stale documentation.

.EXAMPLE
    .\Get-AzureManagementGroupInventory.ps1

.NOTES
    Requires the Az.Resources module and an active Connect-AzAccount session.

.AUTHOR
    Shehryar Hassan
#>

function Get-MgTreeLevel {
    param($GroupId, $Depth = 0)
    $group = Get-AzManagementGroup -GroupId $GroupId -Expand -Recurse
    foreach ($child in $group.Children) {
        [pscustomobject]@{
            Name  = $child.DisplayName
            Type  = $child.Type
            Depth = $Depth
        }
        if ($child.Type -match "managementGroups") {
            Get-MgTreeLevel -GroupId ($child.Name) -Depth ($Depth + 1)
        }
    }
}

$root = (Get-AzManagementGroup | Where-Object { -not $_.ParentId })[0]
Get-MgTreeLevel -GroupId $root.Name | Format-Table -AutoSize

Read it before you run it, and test in a safe tenant first.