Migrating from Set-MsolUserLicense to Set-MgUserLicense

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.


What You Did Previously with Set-MsolUserLicense

In the MSOnline module, you would typically assign or remove licenses using a command like this:

Assign a License to a User

Set-MsolUserLicense -UserPrincipalName "jackie@domain.com" -AddLicenses "contoso:ENTERPRISEPACK"

Bulk Assign Licenses from CSV

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.


What You Should Do Now with Set-MgUserLicense

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.

Example 1: Assign License Using UPN

Set-MgUserLicense -UserId "jackie@7xh7fj.onmicrosoft.com" `
-AddLicenses @{ SkuId = "c42b9cae-ea4f-4ab7-9717-81576235ccac" } `
-RemoveLicenses @()
                                        

Example 2: Assign License Using User ID

Set-MgUserLicense -UserId "cd6cd291-41ba-4b3d-ba70-5f5f07292843" `
-AddLicenses @{ SkuId = "c42b9cae-ea4f-4ab7-9717-81576235ccac" } `
-RemoveLicenses @()
                                        

Important Note:

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.

Example 3: Bulk Assign User Licenses from CSV

Import-Csv "Users.csv" | ForEach-Object {
    Set-MgUserLicense -UserId $_.UserPrincipalName `
    -AddLicenses @{ SkuId = $_.SkuId } `
    -RemoveLicenses @()
}
                                        

How to Find the License SkuId?

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.


What’s Different with Set-MgUserLicense?


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

Conclusion

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:

  • Use -RemoveLicenses @() to ensure proper execution.
  • Fetch SkuIds using Get-MgSubscribedSku.

Head over to M365Corner.com for step-by-step migration kits, tools, and automation-ready scripts for Microsoft 365.



Permission Required

Example:


                                


                                


                                

© Your Site Name. All Rights Reserved. Design by HTML Codex