Forum Discussion
Bulk update Azure AD with user attributes from CSV
- May 08, 2020
Hello Jacob,
Your CSV has to look something like this:
UserPrincipalName;Department;TelephoneNumber
manfreddelaat@domain.nl;IT;0135113333
manfred@domain.nl;IT;0622222222Your Powershell code:
# 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 } } # Array skipped users # $SkippedUsers # Array failed users # $FailedUsersGood luck!
Kind Regards, Manfred de Laat
can you please advice how i can change the manager in bulk for all employees?
there is just one manager account and 130 employees, all of them need to have this manager in Azure AD in order for a flow to work.
thanks
i did it like That:
# Loop trough CSV records
foreach ($CSVrecord in $CSVrecords) {
$upn = $CSVrecord.UserPrincipalName
$upnmanager = $CSVrecord.Manager
$user = Get-AzureADUser -Filter "UserPrincipalName eq '$upn'"
$Manager = Get-AzureADUser -Filter "UserPrincipalName eq '$upnmanager'"
if ($user) {
try{
$user | Set-AzureADUser -City $CSVrecord.City -CompanyName $CSVrecord.CompanyName -Department $CSVrecord.Department -StreetAddress $CSVrecord.StreetAddress -PostalCode $CSVrecord.PostalCode -JobTitle $CSVrecord.JobTitle -Mobile $CSVrecord.Mobile -PhysicalDeliveryOfficeName $CSVrecord.PhysicalDeliveryOfficeName
Set-AzureADUserManager -ObjectId $user.ObjectId -RefObjectId $Manager.objectId
} catch {
$FailedUsers += $upn
Write-Warning "$upn user found, but FAILED to update."
}
}
else {
Write-Warning "$upn not found, skipped"
$SkippedUsers += $upn
}
}
Thanks au lot to all of you !