Disable license of Office 365 users using Powershell

When you assign office 365 license to a user, office 365 services are available to the users like Teams or SharePoint etc. You can enable or disable a specific license for an office 365 account or all office 365 accounts using powershell.

Read More: Export Users DisplayName, UsageLocation, UserPrincipalName, MFA Status, StrongAuthInfo, DefaultAuthMethod from office 365 / Azure AD using PowerShell in CSV

How to disable specific license of Office 365 users using Powershell

  1. Open Powershell and connect to MSOnline Powershell Module using command connect-msolservice. If you do not have MSOnline Module Installed, you can download it by clicking on MSOnline Offline Installer. Follow the instructions to install the Package Install Powershell Module Manually or use command Install-Module MSOnline to install the module. Please install or import this module on windows powershell as msol commands are not supported on Powershell core.
  1. Find the AccountSKUID using below command.
Get-MsolAccountSku | Select AccountSkuId | Sort AccountSkuId
  1. Find the service plan name by using the link: Office 365 service plan. Please check below screenshot as an example for Office 365 E3 the AccountSKUID is ENTERPRISEPACK and Note down the Service Plan which you want to be disabled e.g. <strong>TEAMS1</strong> .
Disable office 365 license using Powershell
Source: Microsoft (https://docs.microsoft.com/en-us/azure/active-directory/users-groups-roles/licensing-service-plan-reference)
  1. Create a LicenseOptions object that disables the Teams service in the licensing plan named techpress:ENTERPRISEPACK (replace this with the accountskuid you get using get-msolaccountsku command output in step 2).
$LO = New-MsolLicenseOptions -AccountSkuId "techpress:ENTERPRISEPACK" -DisabledPlans "TEAMS1"
  1. Set the new license option for a Single user using below command [for one user].
Set-MsolUserLicense -UserPrincipalName -LicenseOptions $LO
  1. Set the new license option for All licensed users at once. Using below commands will disable Teams license for all the users who have office365 E3 plan license assigned or the license you provide in variable $acctSKU.
$AllLicensed = Get-MsolUser -All | Where {$_.isLicensed -eq $true -and $_.licenses.AccountSku.SkuPartNumber -contains ($acctSKU).Substring($acctSKU.IndexOf(":")+1, $acctSKU.Length-$acctSKU.IndexOf(":")-1)}
$AllLicensed | ForEach {Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -LicenseOptions $LO}


In this blog post, we have seen how to disable license of a user or multiple users in office 365 using powershell. You can also assign licenses to the users using powershell as well.


1 thought on “Disable license of Office 365 users using Powershell”

  1. While this is a fantastic post, this doesn’t work in Windows 11. You have to use Microsoft Graph at this point. Do you know how to bulk disable a service such as sway and Yammer using Graph by chance?


Leave a Comment