Update Microsoft Entra ID users with PowerShell (2024)

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:

  1. Type UserPrincipalName at the top of column A
  2. Type JobTitle at the top of column B
  3. List the Microsoft Entra ID users under column A
  4. List the new Job Titles for each user under column B

The CSV file should look like the below example.

Update Microsoft Entra ID users with PowerShell (1)
  1. Create a temp folder on the (C:) drive
  2. Name the file UsersJob.csv
  3. Save as type CSV UTF-8 (Comma delimited)(*.csv)
  4. Click Save
Update Microsoft Entra ID users with PowerShell (2)

Note: It doesn’t matter if there are values present or the values are empty (null) because everything from the CSV will overwrite it.

  1. 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:

  1. Type UserPrincipalName at the top column A
  2. Type Country at the top of column B
  3. List the Microsoft Entra ID users under column A
  4. List the new Country for each user under column B

See the below CSV file example.

Update Microsoft Entra ID users with PowerShell (3)
  1. Create a temp folder on the (C:) drive
  2. Name the file UsersCountry.csv
  3. Save as type CSV UTF-8 (Comma delimited)(*.csv)
  4. Click Save
Update Microsoft Entra ID users with PowerShell (4)

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.

  1. 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:

  1. Type UserPrincipalName at the top column A
  2. Type Country at the top of column B
  3. Type EmployeeId at the top of column C
  4. Type JobTitle at the top of column D
  5. List the Microsoft Entra ID users under column A
  6. List the new Country for each user under column B
  7. List the new Employee IDs for each user under column C
  8. List the new Job titles for each user under column D

See the below CSV file example.

Update Microsoft Entra ID users with PowerShell (5)
  1. Create a temp folder on the (C:) drive
  2. Name the file UsersProperties.csv
  3. Save as type CSV UTF-8 (Comma delimited)(*.csv)
  4. Click Save
Update Microsoft Entra ID users with PowerShell (6)

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.

  1. 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.

Update Microsoft Entra ID users with PowerShell (2024)
Top Articles
Who has won more Wimbledon titles: Federer, Nadal or Djokovic?
The Best K-Dramas Of All Time, Ranked
LOST JEEPS • View forum
Sams Gurnee Gas Price
Used Trucks for Sale in Oneida, TN (with Photos)
The Phenomenon of the Breckie Hill Shower Video Understanding Its Impact and Implications - Business Scoop
Morgandavis_24
Emma Louise (TikTok Star) Biography | Wiki | Age | Net Worth | Career & Latest Info - The Daily Biography
Wow Genesis Mote Farm
Yasmin Boland Daily Horoscope
Beach Umbrella Home Depot
Craigslist Coeur D'alene Spokane
Dr Paul Memorial Medical Center
The Meaning Behind The Song: Waymore's Blues by Waylon Jennings - Beat Crave
Busted Newspaper Randolph County
Stanley Steemer Medford Oregon
Ticket To Paradise Showtimes Near Cmx Daytona 12
Does Cvs Sell Ulta Gift Cards
The latest on the Idaho student murders: Live Updates | CNN
Gncc Live Timing And Scoring
Dtm Urban Dictionary
Natural Appetite Suppressant Tea Fat Loss Diet Plan For Male Bodybuilding (Safe) << Silbonah
Hannaford Weekly Flyer Manchester Nh
The Nearest Dollar Store To My Location
My Fico Forums
Sign in to Office - Microsoft Support
Walgreens Pharmacy On Jennings Station Road
Apple Watch 9 vs. 10 im Vergleich: Unterschiede & Neuerungen
How to get tink dissipator coil? - Dish De
Erfolgsfaktor Partnernetzwerk: 5 Gründe, die überzeugen | SoftwareOne Blog
Korslien Auction
Wym Urban Dictionary
We Tested and Found The Best Weed Killers to Banish Weeds for Good
This Is The Right Order To Watch Every X-Men Movie - Looper
100K NOTES - [DEEPWOKEN - DEEP WOKEN - ROBLOX] | ID 217435304 | PlayerAuctions
Bolly4u Movies Site - Download Your Favorite Bollywood Movies Here
Sherwin Williams Buttercream
Son Blackmailing Mother
Bible Gateway Lookup
Ece 2300 Osu
Paychex Mobile Apps - Easy Access to Payroll, HR, & Other Services
Yuba Sutter Craigslist Free Stuff
7Ohp7
Kayky Fifa 22 Potential
Tillamook Headlight Herald Obituaries
Mazda 6 GG/GG1; GY/GY1 2.3 MPS Test : MPSDriver
Duxa.io Reviews
Craigslist Pets Olympia
Lompoc Record Arrest Log
Stpeach Telegram
Eureka Mt Craigslist
The most memorable songs from '90s movies
Latest Posts
Article information

Author: Frankie Dare

Last Updated:

Views: 5905

Rating: 4.2 / 5 (53 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Frankie Dare

Birthday: 2000-01-27

Address: Suite 313 45115 Caridad Freeway, Port Barabaraville, MS 66713

Phone: +3769542039359

Job: Sales Manager

Hobby: Baton twirling, Stand-up comedy, Leather crafting, Rugby, tabletop games, Jigsaw puzzles, Air sports

Introduction: My name is Frankie Dare, I am a funny, beautiful, proud, fair, pleasant, cheerful, enthusiastic person who loves writing and wants to share my knowledge and understanding with you.