Disable Specific Microsoft 365 License Using Powershell

When you assign a Microsoft 365 license to a user, Microsoft 365 services such as Teams or SharePoint become available to them. You can use PowerShell to enable or Disable a Specific license for a Microsoft 365 account or all Microsoft 365 accounts. Let’s check the steps:

Disable a Specific M365 License Using Powershell

To disable a specific license for a Microsoft 365 user using PowerShell, follow the steps below:

  1. Install the MSOnline Powershell module

Install MSOnline module

Install-module MSOnline

As an alternative, you can install the MSOnline PowerShell module using its offline installer. For more information, please refer to the link: MSOnline Offline Installer. Follow the provided instructions to install the package manually by selecting the ‘Install PowerShell Module Manually‘ option. Please note that MSOL commands are not supported in Powershell core.

  1. Find the AccountSKUID using the command below:

Command to Get AccountSKUID Info

Get-MsolAccountSku | Select AccountSkuId | Sort AccountSkuId
  1. Find the Service Plan Name
    • Refer to the Office 365 service plan link to find the Service Plan that you want to disable. As an example, for Office 365 E3, the AccountSKUID is ENTERPRISEPACK, and the Service Plan or license we want to disable is TEAMS1.
Disable office 365 license using Powershell
Disable a Specific M365 License Using Powershell
  1. Create a LicenseOptions PS variable to disable the Teams service in the licensing plan named techpress:ENTERPRISEPACK (replace this with the AccountSKUID obtained using the Get-MsolAccountSku command output in step 2).

Create LicenceOptions Powershell Variable

$LO = New-MsolLicenseOptions -AccountSkuId "techpress:ENTERPRISEPACK" -DisabledPlans "TEAMS1"
  1. Set the New License Option for a One User

Set LicenceOptions for One user

Set-MsolUserLicense -UserPrincipalName -LicenseOptions $LO
  1. Set the new license option for All licensed users at once. Using the commands below will disable the Teams license for all users who have the Office 365 E3 plan license assigned or the license you provide in the variable $acctSKU.

Disable Teams License for All M365 Licensed Users

acctSKU="techpress:ENTERPRISEPACK"
$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}

1 thought on “Disable Specific Microsoft 365 License 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?

    Reply

Leave a Comment