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:
- 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.
- Find the AccountSKUID using the command below:
Command to Get AccountSKUID Info
Get-MsolAccountSku | Select AccountSkuId | Sort AccountSkuId
- 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.
- Create a
LicenseOptions
PS variable to disable the Teams service in the licensing plan namedtechpress:ENTERPRISEPACK
(replace this with the AccountSKUID obtained using theGet-MsolAccountSku
command output in step 2).
Create LicenceOptions Powershell Variable
$LO = New-MsolLicenseOptions -AccountSkuId "techpress:ENTERPRISEPACK" -DisabledPlans "TEAMS1"
- Set the New License Option for a One User
Set LicenceOptions for One user
Set-MsolUserLicense -UserPrincipalName -LicenseOptions $LO
- 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}
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?