Get-MgUserManager

What is Get-MgUserManager?

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.


Why Use Get-MgUserManager?

With Get-MgUserManager, administrators can:

  • Quickly determine who manages a user.
  • Automate reporting of reporting structures.
  • Export manager details for HR or compliance audits.
  • Enhance onboarding/offboarding workflows by validating reporting lines.

This cmdlet saves time compared to manually navigating through the Microsoft 365 admin center.

Prerequisites

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"

How to Use Get-MgUserManager?

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.


Get-MgUserManager Examples

  • Example 1: Retrieve the Manager Information for a Specific User
  • $managerId = (Get-MgUserManager -UserId "user@domain.com").Id
    $manager = Get-MgUser -UserId $managerId
    $manager | Select-Object Id, DisplayName, UserPrincipalName, Mail
  • Example 2: Retrieve Manager Information for Multiple Users
  • $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
      }
    }
  • Example 3: Output Manager Information to a CSV File
  • $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