In this article, I'll illustrate how to remove all unlicensed users in O365.
Prerequisites
Download and install the following modules.
- Microsoft Online Service Sign-in Assistant for IT Professionals RTW
- Windows Azure Active Directory Module for Windows PowerShell (64-bit version)
Remove Unlicensed Users in Office 365
1) Open PowerShell with elevated privileges.
2) Execute the following command. When you are prompted, enter your O365 global admin account or an account having required privileges.
$credential = Get-Credential
3) Execute the following command to connect to O365.
Connect-MsolService -Credential $credential
4) Execute the following command to remove all unlicensed users.
Get-MsolUser -all | Where-Object {$_.isLicensed -ne "true"}| Remove-MsolUser -Force
5) You can also execute the following command. They both have the same purpose.
Get-MsolUser -All -UnlicensedUsersOnly | Remove-MsolUser -Force