Zip or postal code - bulk upload

Anonymous
2025-02-09T16:01:59.5866667+00:00

Hello

Please i need your help on this issue.

I would like to bulk upload the zip & post code from a csv file for UPN’s in Microsoft Entra.

And also if there is any powershell command.

Microsoft Security | Microsoft Entra | Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bandela Siri Chandana 3,055 Reputation points Microsoft External Staff Moderator
    2025-02-11T07:13:09.05+00:00

    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:

    1. In column A, type UserPrincipalName.
    2. In column B, type PostalCode.
    3. List the Microsoft Entra ID users under column A.
    4. Enter the corresponding new Postal Code for each user under column B.

    The CSV file should look like the example below.

    User's image

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


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.