Update DEPARTMENT in User Contact Details

Modified on Tue, 30 Jun at 5:19 PM

# Connect to AzureAD

Connect-AzureAD


# Get CSV content

$CSVrecords = Import-Csv C:\Users\naufil.mirsinge\Downloads\Import_Contact_Sample.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

        } catch {

        $FailedUsers += $upn

        Write-Warning "$upn user found, but FAILED to update."

        }

    }

    else {

        Write-Warning "$upn not found, skipped"

        $SkippedUsers += $upn

    }

}


# Array skipped users

# $SkippedUsers


# Array failed users

# $FailedUsers

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article