Bulk Updating User Displayname using AzureAD PS Module
Overview
This post will share a PowerShell script for bulk updating user displayname attribute.
AzureAD PowerShell module needs to be installed in the machine, please refer below link to install:
AzureAD Module | Microsoft Learn
After the module gets successfully installed, go ahead and perform the below steps.
1. The Script
# Connect to AzureAD Connect-AzureAD # Get CSV content $CSVrecords = Import-Csv C:\Temp\displaynamenew.csv -Delimiter ";" # Create arrays for skipped and failed users $SkippedUsers = @() $FailedUsers = @() # Loop trough CSV records foreach ($CSVrecord in $CSVrecords) { $upn = $CSVrecord.UserPrincipalName $user = Get-AzureADUser -Filter "userPrincipalName eq '$upn'" if ($user) { try{ $user | Set-AzureADUser -DisplayName $CSVrecord.DisplayName } catch { $FailedUsers += $upn Write-Warning "$upn user found, but FAILED to update." } } else { Write-Warning "$upn not found, skipped" $SkippedUsers += $upn } }
2. Things to Know
In the scirpt the CSV file and the direcotry path should be modified by yourself. And please follow the format like below:
Here’s the user with changed displayname:
3. Limitations & Known Issue
This scirpt with only works for Azure AD cloud only users.
For example, I have some AD synced user in my CSV file list, and they are synced from on-prem AD which failed to update the displayname.
In this scenario, if you have AD synced users, please run the Active Directory module alternatively, then sync users with changed display name to Azure.