Bulk Delete Users

Modified on Tue, 30 Jun at 3:56 PM

# Import required module

Import-Module Microsoft.Graph.Identity.DirectoryManagement

                                

# Get the list of users from a CSV file

$users = Import-Csv -Path "C:\temp\books.csv"

                                

# Loop through each user and soft delete

foreach ($user in $users) {

        Remove-MgUser -UserId $user.UserPrincipalName 

        Write-Output "Soft deleted user: $($user.UserPrincipalName)"

}

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article