Managing user licenses is a core responsibility for Microsoft 365 administrators. Whether onboarding new users, updating subscriptions, or managing trial transitions, assigning licenses efficiently can save you time and reduce errors. In this blog, we’ll explore how to use the powerful Set-MgUserLicense cmdlet from Microsoft Graph PowerShell to assign Microsoft 365 licenses like a pro.
Set-MgUserLicense is a Microsoft Graph PowerShell cmdlet that allows you to assign or remove Microsoft 365 licenses to and from users. You can perform these actions individually or in bulk using a CSV file—making it a valuable tool for both small-scale updates and enterprise-wide operations.
Here’s why IT admins and automation pros prefer Set-MgUserLicense:
Set-MgUserLicense -UserId <String> [-AddLicenses <IMicrosoftGraphAssignedLicense>] [-RemoveLicenses <IMicrosoftGraphGuidCollection>]
Parameters:
Even if you’re not removing licenses, you must explicitly pass -RemoveLicenses @().
Set-MgUserLicense -UserId jackie@7xh7fj.onmicrosoft.com `
-AddLicenses @{SkuId = "c42b9cae-ea4f-4ab7-9717-81576235ccac"} `
-RemoveLicenses @()
💡 This assigns the specified license to Jackie using her UPN. The -RemoveLicenses @() is mandatory even if no license is being removed.
Set-MgUserLicense -UserId cd6cd291-41ba-4b3d-ba70-5f5f07292843 `
-AddLicenses @{SkuId = "c42b9cae-ea4f-4ab7-9717-81576235ccac"} `
-RemoveLicenses @()
🔒 This is useful when you're working with GUIDs instead of UPNs, often the case in automated provisioning.
CSV File Format
UserPrincipalName,SkuId
alice@domain.com,c42b9cae-ea4f-4ab7-9717-81576235ccac
bob@domain.com,c42b9cae-ea4f-4ab7-9717-81576235ccac
PowerShell Script
$CSVPath = "C:\Managers.csv"
$Users = Import-Csv -Path $CSVPath
foreach ($User in $Users) {
Set-MgUserLicense -UserId $User.UserPrincipalName `
-AddLicenses @{SkuId = $User.SkuId} `
-RemoveLicenses @()
}
📁 Automate license assignments for your entire org from a single CSV file.
Use the following command:
Get-MgSubscribedSku | Select SkuPartNumber, SkuId
This returns a list of all license types like ENTERPRISEPACK, BUSINESS_PREMIUM, along with their unique SkuId.
Microsoft Graph API expects both AddLicenses and RemoveLicenses in the request body. Omitting one may result in:
❌ A failed request
⚠️ Unpredictable behavior
Always include both parameters for a reliable execution.
To run Set-MgUserLicense, you must have one of the following delegated or application permissions in Microsoft Graph:
Whether delegated or application based permission, ensure admin consent has been granted for these permissions.
If the user already has the specified license assigned, the cmdlet will complete without making changes. However, if you attempt to reassign the exact same license without changes (e.g., service plans within the license), it won’t affect the current configuration unless you modify the service plans specifically using a more detailed license configuration script.
The Set-MgUserLicense cmdlet empowers administrators to handle Microsoft 365 licensing efficiently—from one-off assignments to full-blown bulk operations. With proper structure, permission, and a clear understanding of SkuId values, you can automate a critical part of your user lifecycle management with just a few lines of PowerShell.
🚀 Pro Tip: Always run your scripts on a few test users before applying bulk operations.
Did You Know? Managing Microsoft 365 applications is even easier with automation. Try our Graph PowerShell scripts to automate tasks like generating reports, cleaning up inactive Teams, or assigning licenses efficiently.
Ready to get the most out of Microsoft 365 tools? Explore our free Microsoft 365 administration tools to simplify your administrative tasks and boost productivity.
© Your Site Name. All Rights Reserved. Design by HTML Codex