Sometimes, you need to add or change a single or multiple Microsoft Entra ID user information. We will show you how to update one property and multiple properties for a single Microsoft Entra ID user. Also, we will bulk set multiple properties for all Microsoft Entra ID users. In this article, you will learn how to update Microsoft Entra ID users with Microsoft Graph PowerShell.
Table of contents
- Set-AzureADUser and Set-MsolUser deprecated
- Manage Microsoft Entra ID users with PowerShell
- Connect to Microsoft Graph PowerShell
- Update single Microsoft Entra ID user properties
- Update-MgBetaUser Microsoft Entra ID property
- Change single Microsoft Entra ID user property
- Update multiple properties for a single Microsoft Entra ID user
- Update properties for multiple Microsoft Entra ID users
- Update job title for multiple Microsoft Entra ID users
- Update country for multiple Microsoft Entra ID users
- Bulk update Microsoft Entra ID users multiple properties
- Conclusion
Set-AzureADUser and Set-MsolUser deprecated
Microsoft announced the Set-AzureADUser and Set-MsolUser cmdlets will be deprecated on March 30, 2024. You need to replace the MS Online PowerShell modules with Microsoft Graph PowerShell.
To update a Microsoft Entra ID user property, we will use the Microsoft Graph PowerShell cmdlets.
Manage Microsoft Entra ID users with PowerShell
We created specific articles to manage Microsoft Entra ID users with Microsoft Graph PowerShell:
- Export Microsoft Entra ID users with PowerShell
- Remove Microsoft Entra ID users with PowerShell
- Restore Microsoft Entra ID users with PowerShell
- Update Microsoft Entra ID users with PowerShell (this article)
Connect to Microsoft Graph PowerShell
Before you start, you must Install the Microsoft Graph PowerShell module, including the Microsoft Graph Beta module.
Run the below commands to install the Microsoft Graph module.
Install-Module Microsoft.Graph -Force
Install-Module Microsoft.Graph.Beta -AllowClobber -Force
Important: Always install the Microsoft Graph PowerShell and Microsoft Graph Beta PowerShell modules. That’s because some cmdlets are not yet available in the final version, and they will not work. Update both modules to the latest version before you run a cmdlet or script to prevent errors and incorrect results.
You also need to Connect to Microsoft Graph PowerShell with the below scopes.
Connect-MgGraph -Scopes "User.ReadWrite.All"
Now, you can use the Update-MgUser and Update-MgBetaUser cmdlets with Microsoft Graph PowerShell.
Note: Not all user account properties can be updated by member or guest users with their default permissions without administrator roles.
Update single Microsoft Entra ID user properties
We will show how to change a single Microsoft Entra ID user property with Microsoft Graph PowerShell. Then, we will show how to update multiple properties for a single Microsoft Entra ID user.
Update-MgBetaUser Microsoft Entra ID property
To update the Microsoft Entra ID user account information, we will use the Update-MgBetaUser cmdlet.
You can add the country of a single user. In our example, the user Amanda Hansen does not have a country set in the information details.
Run the below PowerShell command example to add the user country.
Update-MgBetaUser -UserId "Amanda.Hansen@m365info.com" -Country "GB"
It automatically adds the country information for the Microsoft Entra ID user.
Change single Microsoft Entra ID user property
If a user changes to a different department, you might need to edit that for the user. We will use the -Department parameter to add the new information.
In our example, we want to change the from the Sales department to Marketing for the user, Amanda.Hansen@m365info.com.
Run the below PowerShell command example.
Update-MgBetaUser -UserId "Amanda.Hansen@m365info.com" -Department "Marketing"
It immediately updates the job information of the single Microsoft Entra ID user.
Update multiple properties for a single Microsoft Entra ID user
Let’s say you want to update the properties for a specific Microsoft Entra ID user because this user has another job title and a new phone number.
In our example, we will use the -BusinessPhones parameter to add a number and the -JobTitle parameter to change the job for the user Amanda Hansen.
$UserId = (Get-MgUser -UserId "Amanda.Hansen@m365info.com").IdUpdate-MgBetaUser -UserId $UserId -JobTitle "Marketing Manager" -BusinessPhone "+44 20 8885 6673"
To check that the user properties are updated correctly, we need to get the user details.
Get-MgBetaUser -UserId "Amanda.Hansen@m365info.com" | Select DisplayName, BusinessPhones, JobTitle, Mail, City, CompanyName, Department, EmployeeId, StreetAddress, Country
The PowerShell output results will show you added a phone number and changed the job title.
DisplayName : Amanda HansenBusinessPhones : {+44 20 8885 6673}JobTitle : Marketing ManagerMail : Amanda.Hansen@m365info.comCity : LondonCompanyName : NewCompanyDepartment : MarketingEmployeeId : 123StreetAddress : XCountry : GB
Update properties for multiple Microsoft Entra ID users
We will change the property for multiple or all Microsoft Entra ID users with a CSV file. We will also show you how to bulk set multiple properties for all Microsoft Entra ID users from a CSV file.
Update job title for multiple Microsoft Entra ID users
We want to change and set the job title for multiple Microsoft Entra ID users. First, create a new CSV file with all the Microsoft Entra ID users you want to update.
Open Microsoft Excel and type the below data to change and set the job title:
- Type UserPrincipalName at the top of column A
- Type JobTitle at the top of column B
- List the Microsoft Entra ID users under column A
- List the new Job Titles for each user under column B
The CSV file should look like the below example.
- Create a temp folder on the (C:) drive
- Name the file UsersJob.csv
- Save as type CSV UTF-8 (Comma delimited)(*.csv)
- Click Save
Note: It doesn’t matter if there are values present or the values are empty (null) because everything from the CSV will overwrite it.
- Run the below PowerShell script
# Connect to Microsoft GraphConnect-MgGraph -Scopes User.ReadWrite.All# Read the CSV file$users = Import-Csv -Path "C:\temp\UsersJob.csv"# Go through each user in the CSV and update the job titleforeach ($user in $users) { $userPrincipalName = $user.UserPrincipalName $jobTitle = $user.JobTitle # Check if the user exists $existingUser = Get-MgBetaUser -UserId $userPrincipalName -ErrorAction SilentlyContinue if ($existingUser) { # Check if the existing job title matches the new value if ($existingUser.JobTitle -eq $jobTitle) { # Job title already set with the same value Write-Host "User '$userPrincipalName' already has job title '$jobTitle'." -ForegroundColor Cyan } else { # Update the job title Update-MgBetaUser -UserId $userPrincipalName -JobTitle $jobTitle Write-Host "User '$userPrincipalName' updated job title to '$jobTitle' successfully." -ForegroundColor Green } } else { # User not found Write-Host "User '$userPrincipalName' not found." -ForegroundColor Red }}
The PowerShell output results show the following:
- Microsoft Entra ID user updated new job title
- Microsoft Entra ID user already has set the same job title
- Unknown user which can’t be found in Microsoft Entra ID
User 'Brenda.Smith@m365info.com' updated job title to 'Manager' successfully.User 'David.Kent@m365info.com' already has job title 'Trainee'.User 'Julia.Wood@m365info.com' updated job title to 'Chef' successfully.User 'Rene.Gibs@m365info.com' updated job title to 'Team Leader' successfully.User 'Unknown@m365info.com' not found.
Update country for multiple Microsoft Entra ID users
We want to change and set the country for multiple or all Microsoft Entra ID users. First, create a new CSV file with all the Microsoft Entra ID users you want to update.
Open Microsoft Excel and type the below data:
- Type UserPrincipalName at the top column A
- Type Country at the top of column B
- List the Microsoft Entra ID users under column A
- List the new Country for each user under column B
See the below CSV file example.
- Create a temp folder on the (C:) drive
- Name the file UsersCountry.csv
- Save as type CSV UTF-8 (Comma delimited)(*.csv)
- Click Save
Note: If the values for Country are empty (null) or there are values written for some users, then the new values of the CSV will replace them.
- Run the below PowerShell script
# Connect to Microsoft GraphConnect-MgGraph -Scopes User.ReadWrite.All# Read the CSV file$users = Import-Csv -Path "C:\temp\UsersCountry.csv"# Go through each user in the CSV and update the countryforeach ($user in $users) { $userPrincipalName = $user.UserPrincipalName $country = $user.Country # Check if the user exists $existingUser = Get-MgBetaUser -UserId $userPrincipalName -ErrorAction SilentlyContinue if ($existingUser) { # Check if the existing country matches the new value if ($existingUser.Country -eq $country) { # Country already set with the same value Write-Host "User '$userPrincipalName' already has country '$country'." -ForegroundColor Cyan } else { # Update the country Update-MgBetaUser -UserId $userPrincipalName -Country $country Write-Host "User '$userPrincipalName' updated country to '$country' successfully." -ForegroundColor Green } } else { # User not found Write-Host "User '$userPrincipalName' not found." -ForegroundColor Red }}
The PowerShell output results show the following:
- Microsoft Entra ID user updated new country
- Microsoft Entra ID user already has set the same country
- Unknown user which can’t be found in Microsoft Entra ID
User 'Brenda.Smith@m365info.com' updated country to 'US' successfully.User 'David.Kent@m365info.com' already has country 'US'.User 'Julia.Wood@m365info.com' updated country to 'Germany' successfully.User 'Rene.Gibs@m365info.com' updated country to 'DK' successfully.User 'Unknown@m365info.com' not found.
Bulk update Microsoft Entra ID users multiple properties
Let’s say you want to change and set the Country, Employee ID, and Job Title for all the Microsoft Entra ID users. You need to create a CSV file for all the users you want to update.
Note: An excellent approach is first to Export all Microsoft Entra ID users and adjust the CSV file with the new properties for the users that you want to update. Once that is done, you can skip the below steps and go straight to the PowerShell script below.
Open Microsoft Excel and type the below data:
- Type UserPrincipalName at the top column A
- Type Country at the top of column B
- Type EmployeeId at the top of column C
- Type JobTitle at the top of column D
- List the Microsoft Entra ID users under column A
- List the new Country for each user under column B
- List the new Employee IDs for each user under column C
- List the new Job titles for each user under column D
See the below CSV file example.
- Create a temp folder on the (C:) drive
- Name the file UsersProperties.csv
- Save as type CSV UTF-8 (Comma delimited)(*.csv)
- Click Save
Note: If the values for the user properties are empty (null) or there are values present for some users, then the new values of the CSV will replace them.
- Run the below Powershell script
# Connect to Microsoft GraphConnect-MgGraph -Scopes User.ReadWrite.All# Read the CSV file$users = Import-Csv -Path "C:\temp\UsersProperties.csv"# Go through each user in the CSV and update the propertiesforeach ($user in $users) { $userPrincipalName = $user.UserPrincipalName $employeeId = $user.EmployeeId $jobTitle = $user.JobTitle $country = $user.Country # Check if the user exists $existingUser = Get-MgBetaUser -UserId $userPrincipalName -ErrorAction SilentlyContinue if ($existingUser) { # Check if the existing properties match the new values $updateNeeded = $false if ($existingUser.EmployeeId -ne $employeeId) { $existingUser.EmployeeId = $employeeId $updateNeeded = $true } if ($existingUser.JobTitle -ne $jobTitle) { $existingUser.JobTitle = $jobTitle $updateNeeded = $true } if ($existingUser.Country -ne $country) { $existingUser.Country = $country $updateNeeded = $true } if ($updateNeeded) { # Update the user properties Update-MgBetaUser -UserId $userPrincipalName -EmployeeId $employeeId -JobTitle $jobTitle -Country $country Write-Host "User '$userPrincipalName' updated successfully." -ForegroundColor Green } else { Write-Host "User '$userPrincipalName' properties are up to date." -ForegroundColor Cyan } } else { # User not found Write-Host "User '$userPrincipalName' not found." -ForegroundColor Red }}
The PowerShell output results show the following:
- Microsoft Entra ID user updated new Country, EmployeeID, or Job title
- Microsoft Entra ID user already has these properties set
- Unknown user which can’t be found in Microsoft Entra ID
User 'Brenda.Smith@m365info.com' properties are up to date.User 'David.Kent@m365info.com' updated successfully.User 'Julia.Wood@m365info.com' updated successfully.User 'Rene.Gibs@m365info.com' updated successfully.User 'Unknown@m365info.com' not found.
You learned how to update Microsoft Entra ID user properties with MS Graph PowerShell.
Read more: How to set Employee ID for Microsoft 365 users »
Conclusion
You learned how to update Microsoft Entra ID users with Microsoft Graph PowerShell using the Update-MgUser cmdlet. You can change multiple properties for a single user with PowerShell. It’s also possible to bulk set properties for all Microsoft Entra ID users with a CSV file.
Did you enjoy this article? You may also like Assign Microsoft 365 licenses with group-based licensing. Don’t forget to follow us and share this article.