Migrating from Set-AzureADUser to Update-MgUser

With the deprecation of the AzureAD module, administrators must transition their scripts to the Microsoft Graph PowerShell SDK. One commonly used cmdlet that now requires upgrading is Set-AzureADUser, which was used to update Microsoft 365 user properties. The modern alternative is Update-MgUser.

This guide will help you migrate to Update-MgUser by showing what changed, what to use now, and best practices for keeping your scripts future-proof and scalable.


What You Did Previously with Set-AzureADUser

The Set-AzureADUser cmdlet allowed you to update various user attributes using straightforward parameter-based syntax.

Update a User's Display Name and Job Title

Set-AzureADUser -ObjectId "john.doe@contoso.com" `
-DisplayName "Johnathan Doe" `
-JobTitle "Senior Developer"
                            

Enable or Disable a User

Set-AzureADUser -ObjectId "jane.smith@contoso.com" -AccountEnabled $true

Update Address or Contact Info

Set-AzureADUser -ObjectId "alex.wilson@yourdomain.com" `
-City "Seattle" `
-Country "United States"
                            

While these were effective, they depended on a now-deprecated module and offered limited extensibility.


What You Should Do Now with Update-MgUser

In Microsoft Graph PowerShell, use Update-MgUser for all user property modifications. While some properties can still be updated via named parameters, the recommended and flexible method is to use -BodyParameter with a hashtable, especially for bulk updates or nested attributes.

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"
}
                            

Recommendation: Use -BodyParameter for all updates involving multiple fields, uncommon attributes, or automation scenarios. It ensures cleaner, more reliable code and is essential for bulk operations.


What’s Different with Update-MgUser?

Old (Set-AzureADUser) New (Update-MgUser)
Uses -ObjectId Uses -UserId (UPN or GUID)
Accepts named parameters for all Can use named params, but -BodyParameter preferred
Part of AzureAD module Part of Microsoft.Graph.Users module
Limited extensibility Fully Graph-compliant and extensible
No structured body input Supports powerful hashtable input

Conclusion

Migrating from Set-AzureADUser to Update-MgUser is a necessary step to align with Microsoft’s modern identity platform. Whether you're updating job titles, enabling accounts, or running mass updates via CSV, Update-MgUser provides the flexibility, structure, and compatibility required for future-ready scripting.

👉 Use -BodyParameter whenever possible for bulk or advanced updates.



Permission Required

Example:


                                


                                


                                

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