Purge deleted users from Office 365 (O365)

On occasion you may have to force a deletion of a user, or perhaps a user has been deleted but you need to assign that old email address to someone else.

This is when you need to purge deleted users from Office365.

To do so you need to open up powershell and connect to your office 365 tennancy – you can use connect-msolservice to do so,

Next check which deleted users are currently in the recycle bin:

Get-MsolUser -ReturnDeletedUsers

If there is only one, or you wish to remove all users that have been listed:

-ReturnDeletedUsers | Remove-MsolUser -RemoveFromRecycleBin -Force

If you only want to delete and purge a single user from the Recycle bin – you can use the below:

-ReturnDeletedUsers |Remove-MsolUser -UserPrincipalName “[user’s email address]” -RemoveFromRecycleBin -Force

Sorted, you can now re-use the smtp address or recreate the user. for other ways to Purge deleted users see future posts.

Change the username in O365 when syncing with onsite active directory

When creating a new user in Office365 with a hybrid or active directory syn’d setup it is quite common for Office365 to append the .onmicrosoft.com domain to any new address you set up.

This unfortunately cannot be changed by means of GUI, you need to change the username in O365 using powershell.

To change the username in Office 365: 

1. Make sure you have the WAAD module
2. Run PowerShell
3. Type “Connect-MsolService” –> ENTER. Enter your admin credentials for Office 365 –> OK
4. Use the below command to update the primary email address used to log in exchanging parts in bold;

"Set-MsolUserPrincipalName -UserPrincipalName current_email@****.onmicrosoft.com –NewUserPrincipalName [email protected]"  

Nice and easy 🙂

Connect to O365 using Powershell (Windows Azure Active Directory Module )

So you need a quick way to connect to o365 to manage email for either yourself or your clients?

Connect to O365 using Powershell (Windows Azure Active Directory Module )Load up the Azure Directory module, link below:

Type (or copy/paste):
$msolcred = get-credential
connect-msolservice -credential $msolcred


It will then prompt for your Office 365 administrators user/pass.
Hit enter,

You are now connected to your admin console and can now use a whole host of available cmdlets in order to quickly and effectively manage your exchange and Office365 back-end.

See <link to post> for my Top Five Office 365 Powershell commands