The Get-MgUserManager cmdlet in Microsoft Graph PowerShell retrieves the manager of a specific Microsoft 365 user. It’s often used in organizational hierarchy reporting, compliance checks, and workflow automation.
With Get-MgUserManager, administrators can:
This cmdlet saves time compared to manually navigating through the Microsoft 365 admin center.
Before using this cmdlet, install and connect to the Microsoft Graph module with the right permissions:
Install-Module Microsoft.Graph -Scope CurrentUser
Connect-MgGraph -Scopes "User.Read.All"
Syntax (essential parameters):
Get-MgUserManager -UserId
You can retrieve the manager object of a user and, if needed, use Get-MgUser to pull detailed information.
$managerId = (Get-MgUserManager -UserId "user@domain.com").Id
$manager = Get-MgUser -UserId $managerId
$manager | Select-Object Id, DisplayName, UserPrincipalName, Mail
$users = Get-MgUser -Filter "Department eq 'Sales'" -All
foreach ($user in $users) {
$managerId = (Get-MgUserManager -UserId $user.Id).Id
$manager = Get-MgUser -UserId $managerId
[PSCustomObject]@{
UserId = $user.UserPrincipalName
ManagerId = $manager.Id
ManagerDisplayName = $manager.DisplayName
ManagerUPN = $manager.UserPrincipalName
ManagerMail = $manager.Mail
}
}
$users = Get-MgUser -Filter "Department eq 'HR'" -All
$managers = foreach ($user in $users) {
$managerId = (Get-MgUserManager -UserId $user.Id).Id
$manager = Get-MgUser -UserId $managerId
[PSCustomObject]@{
UserId = $user.UserPrincipalName
ManagerId = $manager.Id
ManagerDisplayName = $manager.DisplayName
ManagerUPN = $manager.UserPrincipalName
ManagerMail = $manager.Mail
}
}
$managers | Export-Csv -Path "C:\ManagersInfo.csv" -NoTypeInformation
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