DEV Community

Christos Matskas for The 425 Show

Posted on

Delete an Azure AD B2C tenant programmatically

There are many cases where you may want to programmatically delete an Azure AD B2C instance programmatically. Luckily, most of what we need to do is doable via MS Graph APIs. Quick reminder that MS Graph may not be available for client accounts that use B2C to sign up/in but it's available to admin accounts and can be used to automate or manage a B2C tenant. With that in mind, we're good to go!


  • .NET Core (3.1 or later)
  • VS Code
  • An Azure AD B2C tenant

Necessary steps

Unlike other Azure Resources, Azure AD and B2C require more work to be deleted. When attempting to delete a B2C tenant, the portal present us with a list of actions that need to be completed before we're allowed to blast the resource off the face of the earth. Example below:

Alt Text

Alt Text

Subsequently, we will be tackling these one at a time and in most cases, there will be an associated video stream to show you how we went about it. If you don't want to see me and JP struggling through the process, you can jump straight to the blog post and code repository:

  • Delete all users in an Azure AD Tenant
  • Delete all app registrations in an Azure AD Tenant
  • Delete all associated Azure subscriptions in an Azure AD Tenant
  • Delete all identity providers in an Azure AD Tenant
  • Delete all user flows in an azure AD Tenant

As always, reach out to us if you have any questions and don't forget to join our Discord

Top comments (0)