In this blog, we will learn how to write a PowerShell script which will read principal user name from the CSV file and remove those users from Office 365 account.
a. Connect Windows Azure Active Directory Module for Windows PowerShell.
b. Use the following code snippet to connect with Office 365 tenant.
$UserCredential = Get-Credential
Connect-AzureAD -Credential $UserCredential
a. Execute the following script.
b. Below is a screenshot for my CSV file.
$sInputFile = "D:\deleteuser.csv"
$sColumnName = "UserPrincipalName" $tblDatos = Import - CSV $sInputFile foreach($fila in $tblDatos)
"Deleting user " + $fila.$sColumnName.ToString()
Write - Host - ForegroundColor Yellow "User staring to deleter"
Remove - MsolUser - UserPrincipalName
Write - Host - ForegroundColor Yellow
c. It will ask for confirmation for deleting every user.
d. Press "Yes".
This is how we can use PowerShell script to delete multiple users from Office 365.