Deleting a test tenant today and one of the pre-requisites before I can delete is to remove all App Registrations and Enterprise Applications.
Unfortunately there’s no select all and delete button in the GUI. So here’s what you do:
1 |
Connect-MgGraph -Scopes "Application.ReadWrite.All" |
In the browser window that pops-up, sign in with a Global Admin or Application Admin account (Global Admin usually, coz you also have to delete all users from the tenant so you are likely left with just the Global Admin).
Then do:
1 2 |
Get-MgApplication | %{ Remove-MgApplication -Confirm:$false -ApplicationId $_.Id } Get-MgServicePrincipal | %{ Remove-MgServicePrincipal -ServicePrincipalId $_.Id -Confirm:$false } |
You might get some errors with the latter, as some Enterprise Applications are from Microsoft. Like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
Remove-MgServicePrincipal_Delete: Specified App Principal ID is Microsoft Internal. Status: 400 (BadRequest) ErrorCode: Request_BadRequest Date: 2024-03-03T13:23:48 Headers: Cache-Control : no-cache Transfer-Encoding : chunked Vary : Accept-Encoding Strict-Transport-Security : max-age=31536000 request-id : a6e68670-b3ad-4b9d-bf04-54f121e9b672 client-request-id : 1b8d50f7-89cf-41e6-8e18-fd6335ffba8f x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"West Europe","Slice":"E","Ring":"5","ScaleUnit":"004","RoleInstance":"AM2PEPF0000BE54"}} x-ms-resource-unit : 1 Date : Sun, 03 Mar 2024 13:23:48 GM |
In my case what I was left with were the Graph, SharePoint, and PnP Enterprise Applications. I could delete them from the portal.