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.
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.
Using Update-MgUser offers several advantages:
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.
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.
Update-MgUser -UserId "john.doe@contoso.com" ` -DisplayName "Johnathan Doe" `-JobTitle "Senior Developer"
This approach is simple and intuitive for quick updates.
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.
# 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.
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