Hi @John Peter
Thank you for posting your query on Microsoft Q&A.
Based on your description, I understand that you want to bulk update the ZIP or postal code properties for all user accounts in Microsoft Entra ID using PowerShell with a CSV file.
To achieve this, please follow the steps below:
Create a CSV file containing the user details you want to update.
Open Microsoft Excel and type the below data to change and set the job title:
- In column A, type
UserPrincipalName
. - In column B, type
PostalCode
. - List the Microsoft Entra ID users under column A.
- Enter the corresponding new Postal Code for each user under column B.
The CSV file should look like the example below.
Save the file on your local drive and copy the file path.
Run the following PowerShell script to update the postal codes:
Install-Module Microsoft.Graph -Force
Connect-MgGraph -Scopes "User.ReadWrite.All"
# Read the CSV file
$users = Import-Csv -Path "C:\temp\Userspostalcode.csv"
# Go through each user in the CSV and update the Postal Code
foreach ($user in $users) {
$userPrincipalName = $user.UserPrincipalName
$
# Check if the user exists
$existingUser = Get-MgUser -UserId $userPrincipalName -Property UserPrincipalName,
if ($existingUser) {
# Check if the existing job title matches the new value
if ($existingUser.
#
Write-Host "User '$userPrincipalName' already has
}
else {
# Update the
Update-MgUser -UserId $userPrincipalName -
Write-Host "User '$userPrincipalName' updated
}
}
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 Postal Code
- Microsoft Entra ID user already has set the same Postal Code
- Unknown user which can’t be found in Microsoft Entra ID
Ref: Configure Microsoft 365 user account properties with PowerShell
I hope this information is helpful. Please feel free to reach out if you have any further questions.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".