If you're still using the Set-MsolUserLicense cmdlet from the MSOnline module to assign licenses in Microsoft 365, it's time to migrate to its Graph PowerShell counterpart — Set-MgUserLicense. Microsoft is deprecating the MSOnline module, and moving to Microsoft Graph ensures better performance, enhanced security, and long-term support.
In this guide, we’ll walk through how you used Set-MsolUserLicense, how to achieve the same with Set-MgUserLicense, the differences, and a few essential tips to avoid common errors during the transition.
In the MSOnline module, you would typically assign or remove licenses using a command like this:
Set-MsolUserLicense -UserPrincipalName "jackie@domain.com" -AddLicenses "contoso:ENTERPRISEPACK"
Import-Csv "users.csv" | ForEach-Object {
Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -AddLicenses $_.LicenseSku
}
While simple and direct, this method depended on a friendly license name (like contoso:ENTERPRISEPACK) and didn’t support much flexibility or advanced license control.
In Microsoft Graph PowerShell, the equivalent cmdlet is Set-MgUserLicense, and it offers a more structured and consistent approach by using GUID-based SkuId values.
Set-MgUserLicense -UserId "jackie@7xh7fj.onmicrosoft.com" `
-AddLicenses @{ SkuId = "c42b9cae-ea4f-4ab7-9717-81576235ccac" } `
-RemoveLicenses @()
Set-MgUserLicense -UserId "cd6cd291-41ba-4b3d-ba70-5f5f07292843" `
-AddLicenses @{ SkuId = "c42b9cae-ea4f-4ab7-9717-81576235ccac" } `
-RemoveLicenses @()
The -RemoveLicenses parameter must be included — even if it's just @() (an empty array). Without it, the license will not be assigned, and the cmdlet won't execute properly.
Import-Csv "Users.csv" | ForEach-Object {
Set-MgUserLicense -UserId $_.UserPrincipalName `
-AddLicenses @{ SkuId = $_.SkuId } `
-RemoveLicenses @()
}
Use the Get-MgSubscribedSku cmdlet to list all available licenses and retrieve the SkuId:
Get-MgSubscribedSku | Select SkuPartNumber, SkuId
This step is essential since Graph PowerShell requires the GUID-based SkuId, not the friendly name like ENTERPRISEPACK.
Old (Set-MsolUserLicense) | New (Set-MgUserLicense) |
Uses friendly names like contoso:PACK | Uses GUID-based SkuId values |
No requirement for RemoveLicenses | -RemoveLicenses is mandatory, even if empty |
Limited visibility into licenses | Use Get-MgSubscribedSku for detailed license info |
Part of MSOnline module | Part of Microsoft.Graph.Users module |
Deprecated | Actively maintained and Graph-aligned |
Migrating from Set-MsolUserLicense to Set-MgUserLicense ensures your license assignment scripts are future-proof and Graph-compliant. While the new cmdlet may look slightly more complex, it offers greater precision, bulk support, and aligns with Microsoft’s modern authentication and API practices.
Don’t forget to:
Head over to M365Corner.com for step-by-step migration kits, tools, and automation-ready scripts for Microsoft 365.
© Your Site Name. All Rights Reserved. Design by HTML Codex