Problem:
How do I remove the Exchange Online license to disable the users mailbox in Office 365?
Solution:
The below script will take a .txt file of users and disable all the Exchange licenses for all of them:
Import-Module MSOnline Connect-MsolService $InputFile = Get-Content "C:\Temp\O365Users.txt" $DisabledPlan = New-MsolLicenseOptions -AccountSkuId 'contoso:ENTERPRISEPACK' -DisabledPlans 'EXCHANGE_S_ENTERPRISE' foreach ($o365user in $InputFile ) { Set-MsolUserLicense -UserPrincipalName $o365user -LicenseOptions $DisabledPlan } Get-MsolAccountSku | Where-Object {$_.SkuPartNumber -eq 'ENTERPRISEPACK'}