Get all subscriptions recursive from management groups with PowerShell

$topLvlMgmtGrp = "CHANGETHIS"          # Name of the top level management group
$subscriptions = @()                   # Output array

# Collect data from managementgroups
$mgmtGroups = Get-AzManagementGroup -GroupId $topLvlMgmtGrp -Expand -Recurse

$children = $true
while ($children) {
    $children = $false
    $firstrun = $true
    foreach ($entry in $mgmtGroups) {
        if ($firstrun) {Clear-Variable mgmtGroups ; $firstrun = $false}
        if ($entry.Children.length -gt 0) {
            # Add management group to data that is being looped throught
            $children       = $true
            $mgmtGroups    += $entry.Children
        }
        else {
            # Add subscription to output object
            $subscriptions += New-Object -TypeName psobject -Property ([ordered]@{'DisplayName'=$entry.DisplayName;'SubscriptionID'=$entry.Name})
        }
    }
}

$subscriptions

Force cancelation of subscription in Azure with REST call

Normally you can only cancel/disable a subscription by code if the subscription is empty.

If you add IgnoreResourceCheck=true and thereby still cancel the subscription. This give you the grace time before deletion. Remember to change {subscriptionId} in the URI

https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Subscription/cancel?IgnoreResourceCheck=true&api-version=2021-10-01

Documentation on grace period

https://docs.microsoft.com/en-us/azure/cost-management-billing/manage/cancel-azure-subscription#what-happens-after-subscription-cancellation