Skip to content

Bulk Update AzureAD Users Managers

Updated: at 05:24 PM

Ever had that moment when HR does a bit of rearranging, shifting reporting lines, and suddenly you’re tasked with updating a bunch of accounts? It happens, and here’s where a simple script can be a real lifesaver.

So, you get this export from the HR system – Just a quick adjustment to the column headers, a bit of data tidying, and you’re ready to automate the whole reporting manager update.

It may seem minor- In MS Teams, there’s a useful feature: a mini organizational chart in a user’s contact info. It shows you who their line manager is and who’s in their team. Simple, but handy!

PowerShell Script

#Connect to AzureAD
Connect-AzureAD 

#Import CSV with the Usernames in Column A, and new manager in Column B
$data = Import-Csv "C:\csvexport\hrmanagerexport.csv"

#Iterating through each row in the CSV
foreach ($row in $data)
{
#INFO in the Console
Write-Host "Updating the user :"  $row.'Username'    " manager to "  $row.'Manager Username'  -ForegroundColor Yellow 

#Updating the Manager 
Set-AzureADUserManager -ObjectId (Get-AzureADUser -ObjectId $row.'Username').Objectid -RefObjectId (Get-AzureADUser -ObjectId $row.'Manager Username').Objectid

#Completion info in the console for the specified row
Write-Host "Updated." -ForegroundColor Green

}

✨ Feedback & Suggestions

If you have any suggestions/feedback, you can contact me via my email.