How to update data in azure AD from a csv file?

Azim Iqbal 0 Reputation points

Need to update EmployeeID, Department,City,Country,State,StreetAddress,EmployeeType,EmployeeHireDate for 400 users.

I keep seeing stuff about running Microsoft graph but I’m having issues with that

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
9,990 questions
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
1,862 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Sudipta Chakraborty - MSFT 1,096 Reputation points Microsoft Employee
    # Connect to AzureAD
    # Get CSV content
    $CSVrecords = Import-Csv C:\Temp\Test.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) {
            $user | Set-AzureADUser -Department $CSVrecord.Department -TelephoneNumber $CSVrecord.TelephoneNumber
            } catch {
            $FailedUsers += $upn
            Write-Warning "$upn user found, but FAILED to update."
        else {
            Write-Warning "$upn not found, skipped"
            $SkippedUsers += $upn

    References: [

    @Azim Iqbal : You can check and modify the above-mentioned script based on your requirement.

  2. Marilee Turscak-MSFT 32,546 Reputation points Microsoft Employee

    Hi Azim Iqbal ,

    To see if you receive different results, please try changing this line:

    $CSVrecords = Import-Csv C:\Windows\system32\TempAzureADUserAttributesNSS12.csv -Delimiter ";" 

    To the following:

     $CSVrecords = Import-Csv C:\Windows\system32\TempAzureADUserAttributesNSS12.csv

    Also, please try displaying your file to ensure that Windows isn't adding a double extension:

    dir C:\Windows\system32\TempAzureADUserAttributesNSS12.csv 

    Let me know if this helps and if you are still facing this issue. There are some troubleshooting steps for that script offered in this thread: [


    If the information helped you, please Accept the answer. This will help us and also improve discoverability for others in the community who might be researching similar information.