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.
The Set-MsolUser cmdlet allowed you to update various properties of a Microsoft 365 user account using direct parameter assignments.
Set-MsolUser -UserPrincipalName "john.doe@contoso.com" `
-DisplayName "Johnathan Doe" `
-Title "Senior Developer"
Set-MsolUser -UserPrincipalName "jane.smith@contoso.com" -BlockCredential $false
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.
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.
Update-MgUser -UserId "john.doe@contoso.com" `
-DisplayName "Johnathan Doe" `
-JobTitle "Senior Developer"
Update-MgUser -UserId "jane.smith@contoso.com" -AccountEnabled $true
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.
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 |
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
© Your Site Name. All Rights Reserved. Design by HTML Codex