Migrating from Set-AzureADUserLicense to Set-MgUserLicense

As Microsoft phases out the AzureAD module in favor of the Microsoft Graph PowerShell SDK, it’s important to understand how to transition your license management scripts. One such shift is moving from Set-AzureADUserLicense to Set-MgUserLicense. In this guide, we'll walk through how to make this migration smoothly, along with real-world examples using the modern Graph approach.


What You Did Previously with Set-AzureADUserLicense?

The Set-AzureADUserLicense cmdlet was used to assign or remove licenses for users by referencing either the UserPrincipalName or ObjectId and specifying the license SKU.

Example

Set-AzureADUserLicense -ObjectId "jackie@domain.com" -AssignedLicenses $assignedLicenses

Here, you had to prepare an object containing both SkuId and optionally the disabled plans.

However, the AzureAD module is deprecated, and Microsoft recommends using Graph PowerShell going forward.

What You Should Do Now with Set-MgUserLicense?

With Microsoft Graph, Set-MgUserLicense is the modern, supported way to manage licenses. You now use -UserId, and two mandatory parameters:

  • -AddLicenses — to specify licenses to assign.
  • -RemoveLicenses — must be included even if no licenses are being removed.

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 following command to list all available licenses and retrieve their 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?


Feature AzureAD (Set-AzureADUserLicense) Graph (Set-MgUserLicense)
Module AzureAD Microsoft.Graph.Users
UPN vs ObjectId Supported Supported
License Format License object with SkuId & DisabledPlans Hashtable with SkuId
Required Parameters AssignedLicenses -AddLicenses and -RemoveLicenses
Supports Bulk via CSV Yes Yes
Friendly License Names Allowed ❌ Only GUID-based SkuId accepted
Future Support ❌ Deprecated ✅ Actively Supported

Conclusion

Migrating to Set-MgUserLicense is straightforward once you get comfortable with the required hashtable format and inclusion of -RemoveLicenses. The new cmdlet brings more clarity, extensibility, and aligns with Microsoft’s long-term direction for automation and management using Graph APIs.!

Make the shift today to future-proof your scripts and embrace the power of Microsoft Graph. Visit M365Corner.com for ready-to-use free Microsoft Graph PowerShell tools and step-by-step migration guides built for Microsoft 365 administrators.



Permission Required

Example:


                                


                                


                                

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