Managing reporting relationships in Microsoft 365 is essential for smooth organizational workflows. Whether you're setting up organizational charts, configuring approval hierarchies, or syncing with HR systems, assigning a manager to a user is a vital step. In this blog, we'll walk you through how to use the Set-MgUserManagerByRef cmdlet from Microsoft Graph PowerShell to assign managers efficiently.
Set-MgUserManagerByRef is a Microsoft Graph PowerShell cmdlet that allows administrators to assign or update a manager for a user in Microsoft 365. The relationship is established by referencing the manager’s unique ID (GUID) or User Principal Name (UPN) through an @odata.id URL structure.
This cmdlet simplifies the process of setting managerial hierarchies programmatically across your tenant.
Here are a few reasons why this cmdlet is widely used by IT admins:
Set-MgUserManagerByRef -UserId -BodyParameter <Object>[<CommonParameters>]
Parameters:
Here’s how you can assign a manager to a single user using the Graph PowerShell module:
$Manager = @{
"@odata.id" = "https://graph.microsoft.com/v1.0/users/12345678-90ab-cdef-ghij-klmnopqrstuv"
}
Set-MgUserManagerByRef -UserId "john.doe@company.com" -BodyParameter $Manager
📝 Note: Replace the @odata.id value with the actual Object ID of the manager.
For large organizations, bulk updates are much more efficient. Here's how you can automate manager assignments using a CSV file.
UserPrincipalName,ManagerId
user1@company.com,manager1-id
user2@company.com,manager2-id
$CSVPath = "C:\Managers.csv"
$Users = Import-Csv -Path $CSVPath
foreach ($User in $Users) {
$Manager = @{
"@odata.id" = "https://graph.microsoft.com/v1.0/users/$($User.ManagerId)"
}
Set-MgUserManagerByRef -UserId $User.UserPrincipalName -BodyParameter $Manager
}
📌 Make sure both the user and manager exist and that you have the necessary permissions to perform this operation.
Yes. You need User.ReadWrite.All and Directory.ReadWrite.All permissions with administrative consent.
No. The @odata.id must reference the manager's Object ID via the Graph endpoint URL.
You’ll receive a ResourceNotFound or BadRequest error. Always validate IDs before running bulk operations.
No. To remove a manager, use the Remove-MgUserManager cmdlet instead.
The Set-MgUserManagerByRef cmdlet is a powerful and flexible tool that simplifies the assignment of managers in Microsoft 365. Whether you're working with a single user or handling bulk updates, this cmdlet can help you automate and streamline your administrative processes. Just make sure to use the correct @odata.id format and verify permissions before executing any changes.
💡 Start small with a single user test before scaling your script across the organization.
Did You Know? Managing Microsoft 365 applications is even easier with automation. Try our Graph PowerShell scripts to automate tasks like generating reports, cleaning up inactive Teams, or assigning licenses efficiently.
Ready to get the most out of Microsoft 365 tools? Explore our free Microsoft 365 administration tools to simplify your administrative tasks and boost productivity.
© Your Site Name. All Rights Reserved. Design by HTML Codex