Set-MgUserLicense: Assign and Remove Licenses in PowerShell

2 min read James Futhey Updated November 13, 2026
Microsoft Learn documentation for the Set-MgUserLicense cmdlet showing its PowerShell syntax

Quick answer: Set-MgUserLicense assigns or removes Microsoft 365 licenses through Microsoft Graph PowerShell. Find the SKU, then add it:

Connect-MgGraph -Scopes User.ReadWrite.All, Organization.Read.All
$e5Sku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'SPE_E5'
Set-MgUserLicense -UserId "belindan@contoso.com" -AddLicenses @{SkuId = $e5Sku.SkuId} -RemoveLicenses @()

The user needs a UsageLocation first. Source: Assign Microsoft 365 licenses with PowerShell on Microsoft Learn.

What is Set-MgUserLicense?

Set-MgUserLicense is in the Microsoft.Graph.Users.Actions module. It calls the Microsoft Graph assignLicense API to add or remove licenses for one user, and to turn individual service plans in a license on or off. Direct licensing like this is the alternative to group-based licensing. For the older MSOnline cmdlet, see Set-MsolUserLicense.

Parameter What it does
-UserId The user's object ID or user principal name (UPN)
-AddLicenses Hash tables with a SkuId, and optional DisabledPlans
-RemoveLicenses SKU IDs to remove; pass @() when removing nothing
-BodyParameter The whole request as one hash table instead
-WhatIf Shows what would happen without changing anything

Source: Set-MgUserLicense on Microsoft Learn.

What permissions do you need?

Requirement Value
Least privileged Graph permission LicenseAssignment.ReadWrite.All
Higher privileged options Directory.ReadWrite.All, User.ReadWrite.All
Read available licenses Organization.Read.All
Admin role (delegated) License Administrator, User Administrator or Directory Writers
Personal Microsoft accounts Not supported

Connect with Connect-MgGraph and request the scopes you need.

How do you find the SKU ID?

Get-MgSubscribedSku lists your tenant's licensing plans. Filter by SkuPartNumber:

Get-MgSubscribedSku -All | Select SkuPartNumber, SkuId, ConsumedUnits

Free licenses in a plan are ActiveUnits minus WarningUnits minus ConsumedUnits.

How do you set the usage location?

You can only assign licenses to accounts with UsageLocation set to a two-letter ISO country code, such as US or FR. Accounts synced from on-premises Active Directory don't have one by default.

Find accounts without one:

Get-MgUser -Select Id,DisplayName,UserPrincipalName,UsageLocation,UserType | where { $_.UsageLocation -eq $null -and $_.UserType -eq 'Member' }

Set it:

Update-MgUser -UserId "belindan@contoso.com" -UsageLocation US

How do you find unlicensed users?

Get-MgUser -Filter 'assignedLicenses/$count eq 0' -ConsistencyLevel eventual -CountVariable unlicensedUserCount -All

Without -All, Get-MgUser returns only the first 100 accounts.

How do you assign more than one license?

Pass an array of hash tables:

$e5Sku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'SPE_E5'
$emsSku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'EMSPREMIUM'
$addLicenses = @(
    @{SkuId = $e5Sku.SkuId},
    @{SkuId = $emsSku.SkuId}
)
Set-MgUserLicense -UserId "belindan@contoso.com" -AddLicenses $addLicenses -RemoveLicenses @()

How do you turn off service plans in a license?

Put the plan IDs in DisabledPlans. This assigns Microsoft 365 E5 with Bookings and Customer Lockbox off:

$e5Sku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'SPE_E5'
$disabledPlans = $e5Sku.ServicePlans |
    Where ServicePlanName -in ("LOCKBOX_ENTERPRISE", "MICROSOFTBOOKINGS") |
    Select -ExpandProperty ServicePlanId
$addLicenses = @(
    @{
        SkuId = $e5Sku.SkuId
        DisabledPlans = $disabledPlans
    }
)
Set-MgUserLicense -UserId "belindan@contoso.com" -AddLicenses $addLicenses -RemoveLicenses @()

To keep plans the user already has turned off, read them first with Get-MgUserLicenseDetail and combine:

$userLicense = Get-MgUserLicenseDetail -UserId "belindan@contoso.com"
$userDisabledPlans = $userLicense.ServicePlans |
    Where ProvisioningStatus -eq "Disabled" |
    Select -ExpandProperty ServicePlanId
$newDisabledPlans = $e5Sku.ServicePlans |
    Where ServicePlanName -in ("SWAY", "FORMS_PLAN_E5") |
    Select -ExpandProperty ServicePlanId
$disabledPlans = ($userDisabledPlans + $newDisabledPlans) | Select -Unique

Then pass $disabledPlans in -AddLicenses as above.

How do you remove a license?

Put the SKU ID in -RemoveLicenses and pass an empty -AddLicenses:

$e3Sku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'SPE_E3'
Set-MgUserLicense -UserId "belindan@contoso.com" -AddLicenses @() -RemoveLicenses @($e3Sku.SkuId)

To move a user from E3 to E5, remove E3, then add E5 with a second Set-MgUserLicense call.

How do you copy licenses from another user?

$mgUser = Get-MgUser -UserId "belindan@contoso.com" -Property AssignedLicenses
Set-MgUserLicense -UserId "jamesp@contoso.com" -AddLicenses $mgUser.AssignedLicenses -RemoveLicenses @()

How do you check a user's licenses?

Get-MgUserLicenseDetail -UserId "belindan@contoso.com"

Troubleshooting

Problem Likely cause and fix
Assignment fails for a new or synced user No UsageLocation. Set it with Update-MgUser.
Request rejected when only adding removeLicenses is required by the API. Pass -RemoveLicenses @().
Insufficient privileges Reconnect with LicenseAssignment.ReadWrite.All, and check your admin role.
Plans you turned off came back on Merge the user's existing disabled plans into DisabledPlans first.
Only 100 users returned Add -All to Get-MgUser.

Summary

  • Connect with User.ReadWrite.All (or LicenseAssignment.ReadWrite.All) and Organization.Read.All.
  • Set UsageLocation before assigning.
  • Get SKU IDs from Get-MgSubscribedSku.
  • Always pass -RemoveLicenses, even as @().
  • Use DisabledPlans to turn off service plans, and check results with Get-MgUserLicenseDetail.

Related: Connect-MgGraph, Get-MgUser, Set-MsolUserLicense, Teams Rooms Pro license cost.

Meeting Room 365 turns any iPad or Android tablet into a room display for Exchange and Microsoft 365 calendars. See the features or pricing: $9 a display a month.

Add a display to your office

Every room, on the door.

Live availability on every meeting room. Works with Microsoft 365, Exchange and Google Workspace.