Get-MgUserDirectReport

What is Get-MgUserDirectReport?

The Get-MgUserDirectReport cmdlet in Microsoft Graph PowerShell retrieves the list of users who directly report to a specified user. It helps administrators understand reporting hierarchies and manage organizational structures more effectively.


Why Use Get-MgUserDirectReport?

With Get-MgUserDirectReport, administrators can:

  • Identify direct reports for a manager or leader.
  • Automate HR or compliance reporting.
  • Validate organizational hierarchies during audits.
  • Export reporting data for analysis and record-keeping.

This cmdlet eliminates the need to manually check reporting structures through the Microsoft 365 Admin Center.


Prerequisites

Before using this cmdlet, connect to Microsoft Graph with the required permissions:

Connect-MgGraph -Scopes "User.Read.All"

How to Use Get-MgUserDirectReport?

Syntax (essential parameters):

Get-MgUserDirectReport -UserId  [-ExpandProperty <String[]>] [-Property <String[]>] 

You must supply a UserId (UPN or ObjectId) of the manager to retrieve their direct reports.


Get-MgUserDirectReport Examples

  • Example 1: Retrieve Direct Reports of a Specific User
  • Get-MgUserDirectReport -UserId "samadmin@7xh7fj.onmicrosoft.com"

    This command retrieves a list of users who report directly to Sam Admin.

  • Example 2: Retrieve Full User Details for Each Direct Report
  • # Retrieve the direct reports of the user
    $directReports = Get-MgUserDirectReport -UserId "samadmin@7xh7fj.onmicrosoft.com"
                                                    
    # Check if any direct reports are returned
    if ($directReports.Count -gt 0) {
        # Loop through each direct report and retrieve full user details
        $directReports | ForEach-Object {
            $userId = $_.Id
            $user = Get-MgUser -UserId $userId
            [PSCustomObject]@{
                DisplayName = $user.DisplayName
                JobTitle    = $user.JobTitle
            }
    } | Format-Table -AutoSize
    } else {
    Write-Host "No direct reports found for the specified user."
    }
                                                

    This command fetches the direct reports of Sam Admin, retrieves full details for each, and displays DisplayName and JobTitle.


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