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

Azim Iqbal 0 Reputation points
2023-01-18T18:22:39.7366667+00:00

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

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

2 answers

Sort by: Most helpful
  1. Sudipta Chakraborty - MSFT 731 Reputation points Microsoft Employee
    2023-01-18T19:14:42.2866667+00:00
    # Connect to AzureAD
    Connect-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) {
            try{
            $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: [https://techcommunity.microsoft.com/t5/windows-powershell/bulk-update-azure-ad-with-user-attributes-from-csv/m-p/1374479

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


  2. Marilee Turscak-MSFT 20,676 Reputation points Microsoft Employee
    2023-01-18T23:16:25.1966667+00:00

    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: [https://techcommunity.microsoft.com/t5/windows-powershell/bulk-update-azure-ad-with-user-attributes-from-csv/m-p/1374479

    -

    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.