I need PowerShell script to update user's office location PowerShell script to update bulk user's office location in azure AD with csv file in azure AD with csv file

Mutaz Abdelmajeed 1 Reputation point
2023-10-25T07:49:22.4366667+00:00

I need a PowerShell script to update the user's Office Location attribute Azure AD through a CSV file in bulk.

Thank you!

Mutaz

PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,329 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
20,629 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Andreas Baumgarten 104K Reputation points MVP
    2023-10-25T08:33:13.5533333+00:00

    Hi @Mutaz Abdelmajeed ,

    if your csv looks like this (for example Sample7users.csv):

    CSVfileCopy

    upn,office
    "testpeter@test.net","Home Office"
    "testpaul@test.net","Room 234"
    

    this PowerShell script should work (tested):

    Import-Csv ".\Sample7users.csv" -Delimiter "," -Encoding UTF8 | ForEach-Object {
        $user = Get-AzureADUser -Filter "userPrincipalName eq '$($_.upn)'"
        Set-AzureADUser -ObjectId $user.ObjectID -PhysicalDeliveryOfficeName "$($_.office)"
    }
    

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards

    Andreas Baumgarten