For updating AzureAD user's manager details in bulk create a
csv "managers.csv" where 1st column name is userPrincipalName and the
2nd column name is Manager on desktop. Filled up the details accordingly.
Note: In
Manager section you need to fill up the manager UPN.
Open the powershell and install module Microsoft.Graph by the following command:
Insatall-Module -Name Microsoft.Graph
Connect with module:
Connect-MgGraph -Scopes User.ReadWrite.All, Directory.ReadWrite.All,
Group.ReadWrite.All
Fill up your credential and allow for the permissions.
Now you are connected to MgGraph.
Copy the following script and modify as per your requirements if needed:
$users = Import-CSV "C:\Users\Administrator\Desktop\managers.csv"
$results = @()
foreach ($user in $users){
$NewManager = @{
"@odata.id" = "https://graph.microsoft.com/v1.0/users/" + $user.Manager
}
$result = $null
try {
Set-MgUserManagerByRef -UserId $user.userPrincipalName -BodyParameter
$NewManager
$result = [PSCustomObject]@{
User = $user.userPrincipalName
Status = "Done"
Message = "Manager updated successfully."
}
Write-Host "$($result.User): $($result.Status) - $($result.Message)"
} catch {
$result = [PSCustomObject]@{
User = $user.userPrincipalName
Status = "Error"
Message = $_.Exception.Message
}
Write-Host "$($result.User): $($result.Status) - $($result.Message)"
-ForegroundColor Red
}
$results += $result
}
$results | Export-Csv -Path "C:\Users\Administrator\Desktop\UpdateResults.csv"
-NoTypeInformation
Save it on your desktop as manager.ps1.
On powershell, go to the desktop location and run the script by "./manager.ps1".
You will get the result on terminal and a "UpdateResults" named csv will be created on desktop where you can check the per user result.
0 Comments