Skip to content

Instantly share code, notes, and snippets.

@ranieuwe
Last active February 1, 2021 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ranieuwe/0641322cfc419cbba32231a4013924f0 to your computer and use it in GitHub Desktop.
Save ranieuwe/0641322cfc419cbba32231a4013924f0 to your computer and use it in GitHub Desktop.
Delete all AAD service principals and enterprise app registrations
# This is a quick way to delete all enterprise applications when you want to delete
# an AAD tenant in some cases some of the Enterprise Apps have dangling service principals
# that are hard to see.
# This script iterates over all the principals and tries delete what it can so that that
# the tenant can be deleted. You will see warnings as some service principals can not
# be deleted. This is fine.
## WARNING --- WARNING -- MAKE SURE TO RUN THIS ON THE CORRECT TENANT --- WARNING --- WARNING
Connect-AzureAD -AccountId <USERNAME>@<TENANT>.onmicrosoft.com
Get-AzureADServicePrincipal | ForEach({ Remove-AzureADServicePrincipal -ObjectId $_.objectid })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment