The Set-MgUserManagerByRef cmdlet in PowerShell assigns a user’s manager.
To use the Set-MgUserManagerByRef cmdlet, you must first connect to your Microsoft 365 tenant using the Connect-MGraph
cmdlet. Once you are connected, you can use the Set-MgUserManagerByRef cmdlet.
The syntax to update a user’s manager is given below.
Set-MgUserManagerByRef
-UserId <String>
-OdataId <String>
-BodyParameter <IReferenceUpdate>
[-AdditionalProperties <Hashtable>]
[-OdataType <String>]
[-PassThru]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
In this article, we will discuss using the Set-MgUserManagerByRef cmdlet in PowerShell to assign a manager to the specified user.
How to Update a User’s Manager
To update a user’s manager for the specified user, run the following command.
# Defines the new manager $NewManager = @{"@odata.id"="https://graph.microsoft.com/v1.0/users/d89e3afc-c554-4607-8748-07b78dc7121a"} # Update the manager Set-MgUserManagerByRef -UserId '1f149c47-a670-4f12-a4ac-01423cbafb58' -BodyParameter $NewManager
In the above PowerShell script, the first command defines the new manager and stores it in the $NewManager
variable. The Set-MgUserManagerByRef command sets the manager for the specified user defined by the -UserId parameter with the value provided on the $NewManager
variable.
The output of the above PowerShell script to update a user’s manager is given below.
Conclusion
I hope the above article on how to use the Set-MgUserManagerByRef cmdlet in PowerShell to set the user’s manager is helpful to you.
You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.