🔧 New: User Management Graph PowerShell Toolkit

Simplify user tasks like bulk creation, updates, password resets, deletions, license checks & more — all from one place.

🚀 Launch Toolkit

7 Useful Scripts with Update-MgUser in PowerShell

Updating user details is one of the most common and essential tasks for Microsoft 365 administrators. Whether you're correcting display names, updating phone numbers, changing job titles, or adjusting office locations — the Update-MgUser cmdlet from Microsoft Graph PowerShell makes it easy and efficient.

This article covers 7 practical and beginner-friendly scripts using Update-MgUser, each designed to help you understand how to update user attributes safely and effectively.


Prerequisites

Before running any of the scripts below, install and connect to Microsoft Graph PowerShell:

Install-Module Microsoft.Graph -Scope CurrentUser
Connect-MgGraph -Scopes "User.ReadWrite.All"

Once connected, you're ready to start updating users in your tenant.


  • Example 1: Update a User’s Display Name and Job Title
  • Update-MgUser -UserId "john.doe@contoso.com" -DisplayName "Johnathan Doe" -JobTitle "Senior Developer"

    Explanation:

    This script updates both the display name and job title for john.doe@contoso.com. Useful during promotions, name corrections, or profile standardization.

  • Example 2: Enable a User’s Account
  • Update-MgUser -UserId "jane.smith@contoso.com" -AccountEnabled $true

    Explanation:

    Sets jane.smith@contoso.com as an active user. This is commonly used when reactivating accounts for returning employees or resolving accidental disables.

  • Example 3: Update Multiple User Properties
  • Update-MgUser -UserId "alex.wang@contoso.com" -MobilePhone "+1 555 555 5555" -OfficeLocation "Building 4" -PreferredLanguage "en-US"

    Explanation:

    Updates several fields at once — mobile number, office location, and preferred language. This is ideal for onboarding updates or mass profile corrections.

  • Example 4: Add Additional Email Address
  • Update-MgUser -UserId "mary.jones@contoso.com" -OtherMails @("mary.jones@otherdomain.com")

    Explanation:

    Adds an alternate email address to the OtherMails attribute. Often used when users have external aliases or when migrating from another mail system.

  • Example 5: Update User Principal Name (UPN)
  • Update-MgUser -UserId "old.username@contoso.com" -UserPrincipalName "new.username@contoso.com"

    Explanation:

    Changes the UPN (login name). This is common during name changes, rebranding, or converting old naming conventions.

  • Example 6: Update the City and Country of a User
  • Useful for keeping physical location details accurate, especially for compliance or HR-driven updates.

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

    Explanation:

    Updates the city and country fields using the -BodyParameter hashtable format. Great for multi-location organizations maintaining updated directory data.

  • Example 7: Update a User’s Office Location
  • This example updates the office location for an employee.

    Update-MgUser -UserId "alex.johnson@yourdomain.com" -BodyParameter @{
        officeLocation = "HQ-Block B"
    }

    Explanation:

    Updates officeLocation using -BodyParameter. Often used when employees move desks, floors, or facilities.


Cmdlet Tips

  • Update-MgUser supports both direct parameters (e.g., -DisplayName) and BodyParameter (a hashtable), depending on the property being updated.
  • Use Get-MgUser -UserId <UPN> before updating to confirm the user's current settings.
  • When updating multiple attributes, using -BodyParameter is cleaner and reduces script length.
  • UPN changes can impact login access — always communicate such changes to the user.
  • Not all attributes are writable; some are system-managed and cannot be updated.

Possible Errors and Solutions

Error Cause Solution
Insufficient privileges to complete the operation Missing required scopes Reconnect using Connect-MgGraph -Scopes "User.ReadWrite.All"
Property is read-only Trying to modify a system-managed property Avoid editing unsupported attributes
Request_BadRequest Invalid parameter value Double-check attribute spelling and supported formats
User not found Incorrect UPN or object ID Verify identity using Get-MgUser
DirectoryObjectNotFound Trying to update a deleted or unlicensed account Restore user or assign required licenses

Conclusion

The Update-MgUser cmdlet is a powerful and flexible tool for updating Microsoft 365 user profiles. Whether you’re modifying display names, locations, languages, or enabling accounts, these examples give you a strong foundation for real-world administration tasks.

As you grow more comfortable, you can combine multiple updates into automated workflows to simplify user management even further.


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