Archive for September, 2012

Windows PowerShell cmdlets for Office 365 ~ Manage Users – Part 03

September 9, 2012 7 comments


This is the third article of the Manage Users article series. Herewith I have shown you more PS comdlets you can you use to manage users on Office 365. I always prefer to use PS comdlets to manage the O365 functions it makes my life easier. Most of the stuff can be done which I can not accomplish through the GUI Smile.

In below article I will cover how to

  1. Remove Msol Users.
  2. Remove Users from the Online Recycle Bin.
  3. Remove unlicensed users.


The Remove-MsolUser cmdlet is used to remove a user from the Microsoft Online directory. This cmdlet will delete the user, their licenses, and any other associated data.

I’ll be removing Adam Perera Msol user from the directory. This user assigned with all license services.




Remove-MsolUser –UserPrincipalName




~Remove Users from the Online Recycle Bin~

Here we go we have we have remove a Msol user from the subscription. But this accounts will stick around for 30 days in recycle bin and there’s nothing you can do. If you want to remove the Msol user permanently you have follow below steps. Before going ahead with that will get list of deleted users in the Recycle Bin. You can use the below PS Cmdlets to retrieve the values of UserPrincipalName, objectID   ,

Get-MsolUser –ReturnDeletedUsers | select UserPrincipalName, objectID 



You can use –RemoveFromRecycleBin parameter to delete Msol user permanently with out waiting for 30 days to be automatically deleted from the subscription. But I need to mention one another thing if you want to get –RemoveFromRecycleBin parameter you have to install the latest version of Msol Powershell toolkit which available in below URL’s.

Then you can connect to the Online subscription and carry out the user deletion.

Remove-MsolUser -RemoveFromRecycleBin –ObjectId OBJECTID



Once you done with removing user and run the Get-MsolUser –ReturnDeletedUsers | select UserPrincipalName, objectID you will see the removed user is actually removed from the online recycle bin. Smile. If you still want to do a bulk deletion you have to write a separate PS script to achieve it.


~Remove unlicensed users~

You can retrieve all the Msol users with User Principal Name, Display Name and License Status by using below comndlet,



As you can see above Gill Christ’s License status is False, so we will see how to delete this Unlicensed users by using PS Cmdlet,

Get-MsolUser -all | Where-Object {$_.isLicensed -ne "true"}| Remove-MsolUser -Force




Windows PowerShell cmdlets for Office 365 ~ Manage Users – Part 01

Windows PowerShell cmdlets for Office 365 ~ Manage Users – Part 02

Categories: Office365