Support
 
Phone Live Chat
 
Support
 
US: +1 888 720 9500
 
Intl: +1 925 924 9500
Aus: +1 800 631 268
UK: 0800 028 6590
CN: +86 400 660 8680

Direct Inward Dialing: +1 408 916 9393

 
 
 
 
 

How to remove a Microsoft 365 license from a user

Remove one license or all licenses from a single user, a list of users, or every licensed user with the Microsoft 365 admin center, Microsoft Graph PowerShell, or ADManager Plus.

 
  • Microsoft 365 admin center
  • PowerShell
  • ADManager Plus
  • Why ADManager Plus
  • Real-world use cases
  • FAQ
  • Troubleshooting
 

How to remove Microsoft 365 licenses from users using the Microsoft 365 admin center

Prerequisites for removing Microsoft 365 licenses via the Microsoft 365 admin center

  • Permissions: Sign in with an account that holds at least the License Administrator or User Administrator role.
  • Tools: A web browser with access to the Microsoft 365 admin center.
  • Setup: Check whether the license is assigned directly or through a group. Group-assigned licenses are listed under the group name on the Licenses page.

Steps to remove licenses from one user using Microsoft 365 admin center

  1. In the Microsoft 365 admin center, go to Users > Active users.
  2. Select the row of the user whose license you want to remove.
  3. In the right pane, select Licenses and Apps.
  4. Expand the Licenses section and clear the boxes for the licenses you want to unassign.
  5. Select Save changes.

Steps to remove all licenses from multiple users using Microsoft 365 admin center

  1. Go to Users > Active users.
  2. Select the circle next to the name of each user.
  3. At the top, select Manage product licenses.
  4. In the Manage product licenses pane, select Unassign all, then select Save changes.
  5. Select Done at the bottom of the pane.

Steps to remove one product's license from several users using the Microsoft 365 admin center

  1. Go to Billing > Licenses.
  2. Select the product.
  3. Check the boxes next to the users or groups you want to unassign.
  4. Select Unassign licenses.
Note:

When a license is removed, the Exchange Online data linked to that account is held for 30 days. After the 30-day grace period, the data is deleted and cannot be recovered.

Limitations for removing Microsoft 365 licenses via the Microsoft 365 admin center

  • Licenses bought through a self-service purchase cannot be unassigned by an admin until the admin takes over that subscription.
  • Group-assigned licenses appear under the group name on the Licenses page, so they are removed by changing the group assignment or the user's group membership, not per user.
  • Users are selected manually on screen, so large or repeated cleanups need repeated manual work.

How to remove Microsoft 365 licenses using PowerShell

Prerequisites for removing Microsoft 365 licenses via PowerShell

  • Permissions: Sign in with at least the License Administrator or User Administrator role. Consent to the User.ReadWrite.All scope, which allows assigning and removing licenses, and the Organization.Read.All scope, which allows reading the licenses available in the tenant.
  • Tools: The Microsoft Graph PowerShell SDK. Install it with Install-Module Microsoft.Graph -Scope CurrentUser.
  • Setup: Keep the user principal name (UPN) of each target user ready. For the CSV example below, prepare a file with a UserPrincipalName column.

Steps to remove Microsoft 365 licenses using PowerShell

  1. Connect to your tenant with Connect-MgGraph and request the scopes listed above:
    Connect-MgGraph -Scopes "User.ReadWrite.All","Organization.Read.All"
  2. List the licenses in the tenant to find the SkuId of the license you want to remove:
    Get-MgSubscribedSku -All | Select-Object SkuPartNumber, SkuId, ConsumedUnits
  3. Check which licenses the user holds with Get-MgUserLicenseDetail:
    Get-MgUserLicenseDetail -UserId "jsmith@zylker.com" | Select-Object SkuPartNumber, SkuId
  4. Remove the license from the user. This example removes the SPE_E5 (Microsoft 365 E5) license:
    $e5Sku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'SPE_E5'
    Set-MgUserLicense -UserId "jsmith@zylker.com" -RemoveLicenses @($e5Sku.SkuId) -AddLicenses @{}

Run the command from step 3 again to confirm the license is gone.

Important caveat:

A license inherited only from a group cannot be removed directly from the user. The user must be removed from the licensing group, or the license must be removed from that group.

Remove a license from users listed in a CSV file

The CSV file needs a UserPrincipalName column, with one account on each row:

$usersList = Import-Csv -Path "C:\Temp\Accounts.csv"
$e5Sku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'SPE_E5'
foreach ($user in $usersList) {
    Set-MgUserLicense -UserId $user.UserPrincipalName -RemoveLicenses @($e5Sku.SkuId) -AddLicenses @{}
}

Remove all licenses from every licensed user

This removes every license from every licensed user in the tenant, so add -WhatIf to Set-MgUserLicense for a dry run first. The licensed users come from Get-MgUser:

$licensedUsers = Get-MgUser -Filter 'assignedLicenses/$count ne 0' `
    -ConsistencyLevel eventual -CountVariable licensedUserCount -All `
    -Select UserPrincipalName,DisplayName,AssignedLicenses
foreach ($user in $licensedUsers) {
    $licensesToRemove = $user.AssignedLicenses | Select-Object -ExpandProperty SkuId
    Set-MgUserLicense -UserId $user.UserPrincipalName -RemoveLicenses $licensesToRemove -AddLicenses @{}
}

Supported parameters: Connect-MgGraph

Parameter Description
-Scopes The permission scopes requested for the session, such as User.ReadWrite.All
-TenantId The tenant to sign in to
-NoWelcome Hides the welcome banner after sign-in

Supported parameters: Get-MgSubscribedSku

Parameter Description
-All Returns every subscribed license in the tenant.

Supported parameters: Get-MgUserLicenseDetail

Parameter Description
-UserId The UPN or object ID of the user
-Property Limits the output to specific license detail properties

Supported parameters: Get-MgUser

Parameter Description
-Filter An OData filter, such as assignedLicenses/$count ne 0 or accountEnabled eq false
-ConsistencyLevel Set to eventual for advanced queries such as the $count filter
-CountVariable Stores the total number of matching users in the named variable
-All Returns every matching user, not only the first page
-Select Returns only the listed properties, such as UserPrincipalName and AssignedLicenses
-Property Requests specific properties, such as AssignedLicenses, that are not returned by default

Supported parameters: Set-MgUserLicense

Parameter Description
-UserId The UPN or object ID of the user
-RemoveLicenses The SkuIds of the licenses to remove
-AddLicenses The licenses to add; pass @{} when you are only removing licenses
-WhatIf Shows what would happen without removing anything

Limitations for removing Microsoft 365 licenses via PowerShell

  • Set-MgUserLicense cannot remove licenses assigned through group-based licensing. Remove the user from the group that assigns the license instead.
  • Removing a license starts the 30-day hold on the user's Exchange Online data, after which the data is deleted and cannot be recovered.
  • Scripts give no audit trail or approval step, so a tenant-wide run depends on the admin checking the user list beforehand.

How to remove Microsoft 365 licenses using ADManager Plus

ADManager Plus is a web-based tool for managing AD, Exchange, and Microsoft 365. It removes selected or all Microsoft 365 licenses for one user or many, from a GUI and without scripts.

Prerequisites for removing Microsoft 365 licenses via ADManager Plus

  • Permissions: Log in to ADManager Plus as an administrator.
  • Tools: A Microsoft 365 tenant configured in ADManager Plus.
  • Setup: To pick users from a file, prepare a CSV with an ObjectId or UserPrincipalName header.

Steps to remove Microsoft 365 licenses using ADManager Plus

  1. Log in to ADManager Plus and click the Microsoft 365 tab.
  2. Click Management in the left panel, then click License Management.
  3. Click Assign / remove licenses.
  4. Select Remove selected licenses or Remove all licenses. For Remove selected licenses, select the type of license to remove.
  5. Specify the location of the users.
  6. Select the Microsoft 365 tenant. You can also add OU-based filters.
  7. Find the users by typing their names in the quick search box, or by importing their details from a CSV file.
  8. Select the users and click Apply.
Removing Microsoft 365 licenses from users using ADManager Plus
Removing Microsoft 365 licenses from users in ADManager Plus

How ADManager Plus streamlines Microsoft 365 license removal

  • Bulk license management: Remove selected or all licenses for many users at once, including users in the same group.
  • Automation: Run license removal at set intervals, for example for users on the Disabled users report.
  • License reports: Review who holds which license before you remove anything, and export the results.
  • Delegation: Let help desk technicians handle license changes without raising their native privileges.
  • Orchestration: Revoke licenses as one action inside a larger offboarding flow.

Real-world use cases

Use case 1: Remove all Microsoft 365 licenses from disabled user accounts

This script removes directly assigned licenses from disabled accounts and reports group-assigned licenses it cannot remove, and mailbox data is held for only 30 days after an Exchange Online license is removed, so try it on a test account first.

PowerShell window with the script that removes all licenses from disabled users and its output
Removing all Microsoft 365 licenses from disabled user accounts using PowerShell
Connect-MgGraph -Scopes "User.ReadWrite.All" -NoWelcome
$disabledUsers = Get-MgUser -Filter "accountEnabled eq false" -All `
    -Property Id,UserPrincipalName,AssignedLicenses |
    Where-Object { $_.AssignedLicenses.Count -gt 0 }
foreach ($user in $disabledUsers) {
    $skuIds = $user.AssignedLicenses | Select-Object -ExpandProperty SkuId
    try {
        Set-MgUserLicense -UserId $user.Id -RemoveLicenses $skuIds -AddLicenses @{} -ErrorAction Stop | Out-Null
        Write-Host "Removed $($skuIds.Count) license(s) from $($user.UserPrincipalName)"
    }
    catch {
        Write-Warning "Skipped $($user.UserPrincipalName): $($_.Exception.Message)"
    }
}

Steps using ADManager Plus

ADManager Plus can remove licenses from disabled users on a recurring basis through an automation.

  1. Click the Automation tab, then select Automation from the left pane.
  2. Click Create New Automation in the top-right corner.
  3. Enter a name and a description, such as Remove Microsoft 365 licenses and Remove licenses of disabled user accounts.
  4. In Automation Category, select User Automation.
  5. Select the domain and the OUs, if needed.
  6. In Automation Task/Policy, select Remove Microsoft 365 licenses.
  7. Select the Remove all licenses option, then select the licenses to remove from the list.
  8. In the From Reports section, choose the Disabled users report. To narrow the result, click Add Condition, and click Generate Report to preview it.
  9. In the Run at field, choose how often the task runs: hourly, daily, weekly, monthly, or once.
  10. Turn on Enable notification if you want an alert each time the automation runs.
  11. Click Save, or Save & Run to run it immediately.
ADManager Plus automation that removes Microsoft 365 licenses from users on the Disabled users report
Removing Microsoft 365 licenses from disabled users using an ADManager Plus automation

Use case 2: Remove a user's Microsoft 365 license while keeping the mailbox

The script in the screenshot converts the mailbox to a shared mailbox with Exchange Online PowerShell, confirms the conversion, and then removes the licenses with Microsoft Graph PowerShell, which suits mailboxes of 50GB or less with no in-place archive or litigation hold.

PowerShell window with the script that converts a mailbox to a shared mailbox and removes the licenses and its output
Converting a mailbox to shared and removing the user's licenses using PowerShell
Connect-ExchangeOnline -UserPrincipalName admin@zylker.com -ShowBanner:$false
Connect-MgGraph -Scopes "User.ReadWrite.All" -NoWelcome
$upn = "jsmith@zylker.com"
Set-Mailbox -Identity $upn -Type Shared
$mailbox = Get-Mailbox -Identity $upn
if ($mailbox.RecipientTypeDetails -eq "SharedMailbox") {
    $user = Get-MgUser -UserId $upn -Property Id,UserPrincipalName,AssignedLicenses
    $skuIds = $user.AssignedLicenses | Select-Object -ExpandProperty SkuId
    Set-MgUserLicense -UserId $user.Id -RemoveLicenses $skuIds -AddLicenses @{} | Out-Null
    Write-Host "Converted $upn to a shared mailbox and removed $($skuIds.Count) license(s)"
}
else {
    Write-Host "$upn is not a shared mailbox yet, so no licenses were removed"
}

Steps using ADManager Plus

An automation policy can convert the mailbox first and remove the license after the period you set.

Create the automation policy
  1. Log in to ADManager Plus as an administrator.
  2. Click the Automation tab, then select Automation Policy under Configuration in the left pane.
  3. Click Create New Automation Policy.
  4. Enter a policy name and description, and select the automation category for users.
  5. Under Instant tasks, select Convert to Shared Mailbox from the drop-down list.
  6. Under Successive tasks, choose the period (days, hours, or minutes) after which the next task runs, then select Remove Microsoft 365 licenses from the drop-down list.
  7. Click Save.
ADManager Plus automation policy form with Convert to Shared Mailbox and Remove Microsoft 365 Licenses tasks
Creating an automation policy with a mailbox conversion task and a license removal task in ADManager Plus
Apply the policy in an automation
  1. Click the Automation tab, select Automation from the left pane, and click Create New Automation.
  2. Enter a name and description for the automation.
  3. In Automation Category, select User Automation.
  4. Select the domain and the OUs, if needed.
  5. In Automation Task/Policy, select the automation policy you created.
  6. Choose the users from a report, or click Select more and specify a CSV file in Location of CSV.
  7. In the Run at field, choose how often the automation runs: hourly, daily, weekly, monthly, or once.
  8. Click Save, or Save & Run to run it immediately.
ADManager Plus automation form with the mailbox conversion and license removal policy selected as the task
Applying the automation policy to users in an ADManager Plus automation

The conversion runs first and the license removal follows after the period you set, so the mailbox is already shared when its license is removed. A shared mailbox over 50GB, or one with in-place archiving or a litigation hold, still needs an Exchange Online Plan 2 license.

FAQ

Read the user's assigned licenses with Get-MgUser -Property AssignedLicenses, then pass their SkuIds to the -RemoveLicenses parameter of Set-MgUserLicense. ADManager Plus does the same for many users at once through bulk license management using the Remove all licenses option.

No. Microsoft retired the license assignment cmdlets in the MSOnline and Azure AD PowerShell modules, and Set-MgUserLicense from the Microsoft Graph PowerShell SDK replaces them. Scripts written with Set-MsolUserLicense and an AccountSkuId need to be rewritten with a SkuId after you connect with Connect-MgGraph.

Run Get-MgSubscribedSku -All to list the tenant's licenses with their SkuPartNumber and SkuId, such as SPE_E5. To see one user's licenses, run Get-MgUserLicenseDetail -UserId, or get the license details of a user through the dedicated how-to. ADManager Plus lists the same information in its license reports.

The examples in Microsoft's documentation pass an empty collection for the list you are not using, so supply -AddLicenses @{} when you remove licenses and -RemoveLicenses @() when you add them.

Exchange Online data linked to the account is held for 30 days and then deleted, and the mailbox can no longer be searched with eDiscovery tools. OneDrive files are not deleted right away, but the account becomes unlicensed. It turns read-only after 60 days and is archived after 93 days, even if the user account stays active. Once billing for unlicensed OneDrive accounts is enabled, archived accounts incur storage and reactivation charges, and accounts that stay unpaid are subject to deletion after 365 cumulative unpaid days. Assigning a license before archival restores access. These rules do not apply to Microsoft Education, Government Community Cloud, or Department of Defense tenants.

Yes. When a user account is deleted, the license becomes available to assign to someone else immediately. To do this with PowerShell, learn how to delete Microsoft Entra ID users using Graph PowerShell.

Troubleshooting

The license is assigned through group-based licensing, and Set-MgUserLicense can only remove licenses that were assigned directly. Remove the user from the group that assigns the license, or change the license assignment on the group, then run the script again.

The session does not hold the permissions needed to change licenses, or the signed-in account lacks the License Administrator or User Administrator role. Run Connect-MgGraph again with the User.ReadWrite.All and Organization.Read.All scopes, and sign in with a qualifying account.

The Microsoft Graph PowerShell SDK is not installed or loaded in the current session. Run Install-Module Microsoft.Graph -Scope CurrentUser, open a new PowerShell window, and connect again.

The assignedLicenses/$count filter is an advanced query. Add -ConsistencyLevel eventual and -CountVariable to the Get-MgUser command, as in the all-licensed-users example above.

ADManager Plus Trusted By

The one-stop solution to Active Directory Management and Reporting