Update-MgUser

What is Update-MgUser?

The Update-MgUser cmdlet in Microsoft Graph PowerShell is used to update attributes of Microsoft 365 user accounts. It supports modifying properties such as display names, job titles, office locations, phone numbers, languages, and more.


Why Use Update-MgUser?

Updating user information is a common task for administrators. Automating it with Update-MgUser ensures:

  • Efficiency – make quick updates without manual admin center navigation.
  • Consistency – apply uniform changes across multiple accounts.
  • Scalability – bulk update properties for hundreds of users from a CSV file.
  • Integration – use in scripts for onboarding, departmental changes, or compliance reporting.

Prerequisites

Before running the cmdlet, install the Microsoft Graph module and connect with proper permissions:

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

How to Use Update-MgUser?

Syntax (essential parameters):

Update-MgUser -UserId <UserPrincipalName or UserId> -Property 

You can update a single property (like DisplayName) or pass a hashtable via -BodyParameter for multiple attributes in one command.


Update-MgUser Examples

  • Update a User's Display Name and Job Title
  • Update-MgUser -UserId "john.doe@contoso.com" -DisplayName "Johnathan Doe" -JobTitle "Senior Developer"
  • Enable a User's Account
  • Update-MgUser -UserId "jane.smith@contoso.com" -AccountEnabled $true
  • Update Multiple User Properties
  • Update-MgUser -UserId "alex.wang@contoso.com" -MobilePhone "+1 555 555 5555" -OfficeLocation "Building 4" -PreferredLanguage "en-US"
  • Add Additional Email Address
  • Update-MgUser -UserId "mary.jones@contoso.com" -OtherMails @("mary.jones@otherdomain.com")
  • Update User Principal Name
  • Update-MgUser -UserId "old.username@contoso.com" -UserPrincipalName "new.username@contoso.com"
  • Update the City and Country of a User
  • Update-MgUser -UserId "alex.wilson@yourdomain.com" -BodyParameter @{
        city = "Seattle"
        country = "United States"
    }
                                                
  • Update a User’s Office Location
  • Update-MgUser -UserId "alex.johnson@yourdomain.com" -BodyParameter @{
        officeLocation = "HQ-Block B"
    }
                                                
  • Bulk Update User Attributes From CSV
  • # Connect to Microsoft Graph
    Connect-MgGraph -Scopes "User.ReadWrite.All"
                                                    
    # 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 {
        $updateParams = @{
            DisplayName = $user.DisplayName
            JobTitle    = $user.JobTitle
            Department  = $user.Department
            MobilePhone = $user.MobilePhone
        }
        Update-MgUser -UserId $user.UserPrincipalName -BodyParameter $updateParams
        Write-Host "Successfully updated user: $($user.UserPrincipalName)"
        }
        catch {
            Write-Host "Failed to update user: $($user.UserPrincipalName). Error: $_"
        }
    }
    
    # Disconnect from Microsoft Graph
    Disconnect-MgGraph

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