How to Use Update-MgUser to Update Microsoft 365 Users?

Managing user accounts in Microsoft 365 often involves updating user details like job titles, phone numbers, office locations, or enabling/disabling accounts. The Update-MgUser cmdlet from the Microsoft Graph PowerShell SDK provides a modern and efficient way to make these changes—whether you're updating a single user or performing bulk operations.

In this blog, we’ll walk you through what Update-MgUser does, when to use it, its syntax, real-world examples, and frequently asked questions.

What is Update-MgUser?

Update-MgUser is a Microsoft Graph PowerShell cmdlet used to modify properties of Microsoft 365 user accounts. It allows administrators to update a wide range of user attributes such as display name, job title, phone numbers, and more—all using the Microsoft Graph API under the hood.

Why Use Update-MgUser?

Using Update-MgUser offers several advantages:

  • It's Graph-powered and future-proof compared to older Set-MsolUser or Set-AzureADUser cmdlets.
  • It supports both individual and bulk updates.
  • You can update multiple properties at once using the -BodyParameter.
  • It works seamlessly across all environments using the Microsoft.Graph SDK.

Cmdlet Syntax

Update-MgUser -UserId <String> [-AccountEnabled <Boolean>] [-DisplayName <String>] [-JobTitle <String>] [-MobilePhone <String>] [-OfficeLocation <String>] [-OtherMails <String[]>] [-PreferredLanguage <String>] [-Surname <String>] [-UserPrincipalName <String>] 

You can also pass multiple properties together using the -BodyParameter hashtable, especially useful for bulk operations or grouped updates.

Usage Examples

Note:You don't always need -BodyParameter for updating a single or few properties. However, using -BodyParameter is recommended when updating multiple fields at once, particularly in loops or automation.

Example 1: Update a User's Display Name and Job Title (without -BodyParameter)

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

This approach is simple and intuitive for quick updates.

Example 2: Update the City and Country of a User (with -BodyParameter)

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

Using -BodyParameter allows you to batch multiple attributes and keep the syntax clean.

Example 3: Bulk User Update from CSV

# Path to the CSV file
$csvPath = "C:\Path\To\Your\CSV\users.csv"
                                            
# Import the CSV file
$users = Import-Csv -Path $csvPath
                                            
# Loop through each user and update attributes
foreach ($user in $users) {
    try {
        # Prepare the update payload
        $updateParams = @{
        DisplayName = $user.DisplayName
        JobTitle    = $user.JobTitle
        Department  = $user.Department
        MobilePhone = $user.MobilePhone
        }
                                                    
        # Update the user attributes
        Update-MgUser -UserId $user.UserPrincipalName -BodyParameter $updateParams
                                                    
        Write-Host "Successfully updated user: $($user.UserPrincipalName)"
    }
    catch {
        Write-Host "Failed to update user: $($user.UserPrincipalName). Error: $_"
    }
}
                                            

Make sure your CSV contains headers like: UserPrincipalName, DisplayName, JobTitle, Department, MobilePhone.

Frequently Asked Questions

  • Is -BodyParameter always required?
    No. It is optional for individual property updates but required/recommended for multiple property updates.
  • Can I disable a user account using Update-MgUser?
    Yes, use -AccountEnabled $false or include it in -BodyParameter.
  • What permissions are required?
    You need delegated or application permissions like User.ReadWrite.All.
  • Can I disable a user account using Update-MgUser?
    Yes, use -AccountEnabled $false or include it in -BodyParameter.

Use Cases

  • Modify job title or department across a team after reorganization
  • Enable or disable user accounts in bulk
  • Update office locations after a physical move
  • Fix display names or mobile numbers from HR system exports
  • Automate user profile updates during onboarding/offboarding

Conclusion

The Update-MgUser cmdlet offers a powerful, flexible, and Graph-based approach to managing Microsoft 365 user attributes. Whether you're making a quick fix or automating a bulk update process, this cmdlet can streamline your administrative workflow.

Start using Update-MgUser today and modernize how you manage user data in Microsoft 365!

Did You Know? Managing Microsoft 365 applications is even easier with automation. Try our Graph PowerShell scripts to automate tasks like generating reports, cleaning up inactive Teams, or assigning licenses efficiently.

Ready to get the most out of Microsoft 365 tools? Explore our free Microsoft 365 administration tools to simplify your administrative tasks and boost productivity.

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