Simplify user tasks like bulk creation, updates, password resets, deletions, license checks & more — all from one place.
🚀 Launch ToolkitThis guide explores how to use Update-MgUser cmdlet in Graph PowerShell to modify user attributes in your Microsoft 365 tenant. Learn how to update properties such as display name, phone number, and department, and explore examples for both single and bulk user updates.
Updating user information in Microsoft 365 is a common administrative task. The Update-MgUser cmdlet in the Microsoft Graph PowerShell module provides a powerful way to update user properties. This article will cover the Update-MgUser cmdlet basics like the cmdlet prerequisites, cmdlet syntax with parameter explanations, various usage examples, helpful tips, common errors involved with solutions.
Install-Module -Name Microsoft.Graph -Scope CurrentUser
Connect-MgGraph -Scopes "User.ReadWrite.All"
Update-MgUser -UserId <String> [-AccountEnabled <Boolean>] [-DisplayName <String>] [-JobTitle <String>] [-MobilePhone <String>] [-OfficeLocation <String>] [-OtherMails <String[]>] [-PreferredLanguage <String>] [-Surname <String>] [-UserPrincipalName <String>] []
-UserId:
The unique identifier of the user to update. This can be the user's Id, UserPrincipalName, or Email.-AccountEnabled:
Specifies whether the user's account is enabled or disabled.-DisplayName:
The user's display name.-JobTitle:
The user's job title.-MobilePhone:
The user's mobile phone number.-OfficeLocation:
The user's office location.-OtherMails:
Additional email addresses for the user.-PreferredLanguage:
The user's preferred language.-Surname:
The user's last name.-UserPrincipalName:
The user's principal name (user's sign-in name).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.wang@contoso.com" -MobilePhone "+1 555 555 5555" -OfficeLocation "Building 4" -PreferredLanguage "en-US"
Update-MgUser -UserId "mary.jones@contoso.com" -OtherMails @("mary.jones@otherdomain.com")
Update-MgUser -UserId "old.username@contoso.com" -UserPrincipalName "new.username@contoso.com"
Useful for updating physical location information for directory accuracy or compliance.
Update-MgUser -UserId "alex.wilson@yourdomain.com" -BodyParameter @{
city = "Seattle"
country = "United States"
}
This updates the officeLocation property for the user alex.johnson@yourdomain.com to "HQ-Block B" — useful for reflecting seating changes or facility updates in the directory.
Update-MgUser -UserId "alex.johnson@yourdomain.com" -BodyParameter @{
officeLocation = "HQ-Block B"
}
CSV File Example:
UserPrincipalName,JobTitle,Department,OfficeLocation
johndoe@domain.com,Manager,Sales,New York
janedoe@domain.com,Engineer,IT,San Francisco
$users = Import-Csv -Path "C:\Path\To\Users.csv"
foreach ($user in $users) {
$userParams = @{
JobTitle = $user.JobTitle
Department = $user.Department
OfficeLocation = $user.OfficeLocation
}
Update-MgUser -UserId $user.UserPrincipalName -BodyParameter $userParams
}
Error Message | Solution |
Insufficient Permissions Error: You might encounter an error indicating insufficient permissions. | Ensure your account has the User.ReadWrite.All permission. Reconnect with the required scopes if necessary.
|
Invalid UserId Error: Specifying an incorrect or non-existent UserId will result in an error. | Verify UserId exists using Get-MgUser cmdlet before performing the update operation. |
Incorrect Parameter Values Error: Providing invalid values for parameters (e.g., improperly formatted email addresses). | Ensure all parameter values are correctly formatted and valid. Double-check the input data. |
Update-MgUser -UserId "<UserPrincipalName>" -BodyParameter @{ "displayName" = "New Display Name" }
Can I update multiple users at once using Update-MgUser?
Yes, bulk updates can be performed using a CSV file. Prepare the file with the following format:
UserPrincipalName,DisplayName,Department
user1@domain.com,New Display Name 1,Sales
user2@domain.com,New Display Name 2,Marketing
$Users = Import-Csv -Path "C:\Path\To\File.csv"
foreach ($User in $Users) {
$Body = @{
"displayName" = $User.DisplayName
"department" = $User.Department
}
Update-MgUser -UserId $User.UserPrincipalName -BodyParameter $Body
}
try {
Update-MgUser -UserId "user@domain.com" -BodyParameter $params
} catch {
$_.Exception.Message
}
Update-MgUser
cmdlet can only modify certain properties of a user object. Attempting to update read-only or system-managed fields (like UserPrincipalName
for synced users) will result in errors.
Update-MgUser
will fail with a Property is read-only
error.Get-MgUser
for Targeted UpdatesGet-MgUser
into Update-MgUser
to update specific user accounts based on conditions like department, city, or usage.Get-MgUser -Filter "department eq 'Sales'" -All |
ForEach-Object {
Update-MgUser -UserId $_.Id -BodyParameter @{ city = "Chicago" }
}
The Update-MgUser cmdlet is a versatile tool for updating user information in Microsoft 365. By understanding its parameters and usage, you can efficiently manage user properties. Remember to handle errors gracefully and verify your input data to avoid common pitfalls. With these practices, you can ensure smooth and effective updates to your organization's user information.
Note: Updating a user via Graph API requires a PATCH
request to /users/{id}
. You only need to send the fields that need to be modified in the request body.
Update a Single User
# Replace with actual UPN or user ID
$userId = "john.sample@yourtenant.onmicrosoft.com"
# Define the update payload
$updatePayload = @{
jobTitle = "Project Manager"
department = "IT"
city = "Seattle"
}
# Send the PATCH request using Graph API
Invoke-MgGraphRequest -Method PATCH -Uri "https://graph.microsoft.com/v1.0/users('$userId')" -Body ($updatePayload | ConvertTo-Json -Depth 10)
Update Users in Bulk from CSV
# Sample CSV headers: userPrincipalName,jobTitle,department,city
$users = Import-Csv -Path "C:\Users\admin\Documents\update-users.csv"
foreach ($user in $users) {
$updatePayload = @{
jobTitle = $user.jobTitle
department = $user.department
city = $user.city
}
# Send PATCH request for each user
$uri = "https://graph.microsoft.com/v1.0/users('$($user.userPrincipalName)')"
Invoke-MgGraphRequest -Method PATCH -Uri $uri -Body ($updatePayload | ConvertTo-Json -Depth 10)
}
CSV Format Example
userPrincipalName,jobTitle,department,city
john.sample@yourtenant.onmicrosoft.com,Project Manager,IT,Seattle
jane.admin@yourtenant.onmicrosoft.com,System Analyst,Finance,New York
💡 Only include the fields you want to update. Any omitted fields will remain unchanged.
Required Permissions
To update user profile properties, you need one of the following:
Graph API Documentation
👉 PATCH /users/{id} - Microsoft Graph v1.0
Suggested Reading
© m365corner.com. All Rights Reserved. Design by HTML Codex