Migrating from Set-MsolUser to Update-MgUser

As Microsoft continues phasing out the MSOnline module, it's time to retire Set-MsolUser from your scripts and embrace the modern, Graph-powered alternative: Update-MgUser. While the names are different, the purpose remains the same—modifying user properties in Microsoft 365. However, the way you structure your updates has evolved.

In this guide, we’ll walk through how to migrate from Set-MsolUser to Update-MgUser, show practical examples, and explain the key differences.


What You Did Previously with Set-MsolUser

The Set-MsolUser cmdlet allowed you to update various properties of a Microsoft 365 user account using direct parameter assignments.

Examples

Update Display Name and Job Title

Set-MsolUser -UserPrincipalName "john.doe@contoso.com" `
-DisplayName "Johnathan Doe" `
-Title "Senior Developer"
                                        

Enable or Disable a User

Set-MsolUser -UserPrincipalName "jane.smith@contoso.com" -BlockCredential $false

Update City and Country

Set-MsolUser -UserPrincipalName "alex.wilson@yourdomain.com" `
-City "Seattle" `
-Country "United States"
                                        

While this syntax was simple and direct, it was tightly coupled with the now-deprecated MSOnline module.


What You Should Do Now with Update-MgUser

The modern replacement is Update-MgUser, which is part of the Microsoft Graph PowerShell SDK. This cmdlet allows more flexibility and aligns with the structure of Graph API operations.

Example 1: Update a User’s Display Name and Job Title

Update-MgUser -UserId "john.doe@contoso.com" `
-DisplayName "Johnathan Doe" `
-JobTitle "Senior Developer"
                                        

Example 2: Update or Enable a User's Account

Update-MgUser -UserId "jane.smith@contoso.com" -AccountEnabled $true

Example 3: Update the City and Country Using a Hashtable

Update-MgUser -UserId "alex.wilson@yourdomain.com" -BodyParameter @{
    city    = "Seattle"
    country = "United States"
}
                                        

💡 Note:When modifying multiple properties or less-common ones, always use -BodyParameter with a hashtable. This approach is more reliable and extensible, especially for bulk updates or automation.


What’s Different with Update-MgUser?


Old (Set-MsolUser) New (Update-MgUser)
Uses -UserPrincipalName Uses -UserId (can still be UPN)
Updates via named parameters Updates via named parameters or hashtable
Part of MSOnline (deprecated) Part of Microsoft Graph (actively supported)
Limited extensibility Supports all Graph user object properties
No native hashtable support Supports dynamic updates with -BodyParameter

Conclusion

The transition from Set-MsolUser to Update-MgUser represents more than just a syntax change — it’s a shift to a more secure, flexible, and future-ready approach using Microsoft Graph.

While it may take a few extra lines to adapt at first (especially with the hashtable method), the payoff is significant: more control, wider property support, and alignment with Microsoft’s modern administration stack.

Explore more Graph PowerShell resources at M365Corner.com



Permission Required

Example:


                                


                                


                                

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