Thank you for your post and I apologize for the delayed response!
In order to delete your B2C tenant using PowerShell, please make sure you run the Invoke-RestMethod
Delete command as the last step in the deletion process. For more info - How do I delete my Azure AD B2C tenant?
- When creating my test B2C tenant and trying to delete it right after creation. I didn't realize that I still needed to follow the steps in order to delete my tenant.
-
Once I removed the **b2c-extensions-app
**and selected "Yes" under the "Access management for Azure resources" Azure AD property, I was able to successfully delete my B2C tenant via PowerShell.
$SubscriptionId = "<SubID>"
$ResourceGroupName = "B2C"
$ManagementAzureUri = "https://management.azure.com/"
$B2CName = "deleteB2CTenant.onmicrosoft.com"
$ApiVersion = "2021-04-01"
$access_token = Get-AzAccessToken -ResourceUrl "https://management.azure.com/"
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/json")
$headers.Add("Authorization", 'Bearer ' + $access_token.Token)
$b2cUri = $ManagementAzureUri + "subscriptions/$SubscriptionId/resourceGroups/$ResourceGroupName/providers/Microsoft.AzureActiveDirectory/b2cDirectories/$B2CName" + "?api-version=$ApiVersion"
Invoke-RestMethod -Uri $b2cUri -Method 'DELETE' -Headers $headers -Verbose
I hope this helps!
If the information helped address your question, please Accept the answer. This will help us and also improve searchability for others in the community who might be researching similar information.