Delete Azure ad b2c bulk users using powershell

Jhon 1 Reputation point
2020-09-10T07:28:11.437+00:00

Hello Team,

I'm trying to delete the Azure ad b2c users using bulk option from azure adb2c portal and ended up with the error.

currently our users with their signinnames shows as user principle name in azure ad b2c portal. but when i try to delete using bulk operation through csv file. It is not able to find the user with specific UPN and we realized that in the backedend the UPN is different.

error: 23715-image.png
can anyone help us?

we want to delete plenty of users on azure ad b2c

regards,
John

Microsoft Security | Microsoft Entra | Microsoft Entra External ID
{count} votes

3 answers

Sort by: Most helpful
  1. AmanpreetSingh-MSFT 56,951 Reputation points Moderator
    2020-09-10T09:25:50.57+00:00

    Hi @Jhon ,

    To delete users in bulk, you can follow below steps:

    • Navigate to Azure AD B2C > Users > All Users > Bulk Operations > Download Users. This will download a list of all users in the B2C tenant with their original UPN, Display name, Mail, AlternateEmailAddress and so on in a CSV file.
    • Navigate to Azure AD B2C > Users > All Users > Bulk Operations > Bulk Delete and download CSV file.
    • From the file downloaded in step 1, copy the UPNs of the users that you want to delete and paste in the file downloaded in step 2, as shown below:
      23710-image.png
    • Navigate to Azure AD B2C > Users > All Users > Bulk Operations > Bulk Delete and upload the updated file.
    • Type 'Yes' to continue and click on submit.

    Note: This will soft delete all the users listed in the uploaded file. Which means the users will be moved to Deleted users and then gets hard/permanently deleted automatically after 30 days. If you want to permanently delete the users before 30 days, you'll have to manually delete the users from the Deleted users blade.

    -----------------------------------------------------------------------------------------------------------

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.

    0 comments No comments

  2. Jhon 1 Reputation point
    2020-09-18T15:25:18.483+00:00

    Hi Aman,

    thanks for your answer. But i'm looking for more to use power-shell. The answer which you have is already known.

    0 comments No comments

  3. AmanpreetSingh-MSFT 56,951 Reputation points Moderator
    2020-09-21T05:34:09.843+00:00

    Hi @Jhon Please find below the script for this purpose:

    Connect-MsolService #sign-in using Global Admin of your B2C tenant. User should be Member of the tenant and not signed-up or guest user.  
    $users = import-csv C:\temp\users.csv  
    foreach ($usr in $users)  
    {  
    Remove-MsolUser -UserPrincipalName $usr.upn -Force  
    }  
    

    Below is how the user.csv file looks:
    26037-image.png

    -----------------------------------------------------------------------------------------------------------

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.