Intro

Here how to delete Exchange Online Users with PowerShell script.

Prerequisites

Instructions

users1@domain.net
users2@domain.net
users3@domain.net
[...]
usersN@domain.net
Import-Module MSOnline
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
Connect-MsolService -Credential $UserCredential

# Put the users into an array
$array = Get-Content C:\Users\shebangthedolphins\Desktop\userlist.txt

foreach($item in $array){
             Write-Host "$item" #show current user
             get-mailbox -identity "$item" #test if the user exist
             #Remove-MsolUser -UserPrincipalName "$item"
             #remove-mailuser -identity "$item"

	     # remove the account (mailboxe + account)
             Remove-MsolUser -UserPrincipalName "$item" -Force 
	     # log if it is OK or not
             if ($? -eq '$True') { 
                "$item : OK" | out-file "C:\Users\shebangthedolphins\Desktop\result.txt" -Append
             } else {
                "$item : KO" | out-file "C:\Users\shebangthedolphins\Desktop\result.txt" -Append
             }
             #Remove-Mailbox -Identity "$item" -Permanent $true
}
Licence Creative Commons
This website http://shebangthedolphins.net is licensed to the public under a licence Creative Commons Attribution licence.
Contact :