Simplify user tasks like bulk creation, updates, password resets, deletions, license checks & more — all from one place.
🚀 Launch ToolkitThe Get-MgUserDirectReport cmdlet is a powerful tool within the Microsoft Graph PowerShell module that allows administrators to retrieve a list of users who report directly to a specified user. This cmdlet can be instrumental in managing organizational hierarchies, generating reports, and ensuring compliance with company policies.
In this article, we will delve into the syntax, usage examples, common use cases, and potential errors along with their solutions.
The basic syntax for the Get-MgUserDirectReport cmdlet is as follows:
Get-MgUserDirectReport -UserId <String> [-ExpandProperty <String[]>] [-Property <String[]>] [<CommonParameters>]
Least permission required: User.Read.All
Get-MgUserDirectReport -UserId "samadmin@7xh7fj.onmicrosoft.com"
This command retrieves a list of users who report directly to Sam Admin.
# 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 the full user details for each direct report, and displays the DisplayName, JobTitle properties.
Error Message | Solution |
User not found | Verify that the UserId is correct and that the user exists in the directory. You can use the Get-MgUser cmdlet to confirm the user details:Get-MgUser -UserId "samadmin@7xh7fj.onmicrosoft.com" |
Error: "Insufficient privileges" | Ensure that your account has the necessary permissions to retrieve user data. You might need to be a Global Administrator or User Administrator or have appropriate directory roles assigned. |
Get-MgUserDirectReport
cmdlet fetches only direct reports, not the entire reporting hierarchy.Get-MgUserDirectReport
returns no results, it may be because the user's manager is not assigned in Azure AD.The Get-MgUserDirectReport cmdlet is an essential tool for administrators managing organizational hierarchies within Microsoft 365. By leveraging this cmdlet, you can efficiently retrieve and manage direct report information, ensuring better oversight and compliance. Whether generating reports or integrating data, this cmdlet offers the flexibility and power needed for robust user management.
© m365corner.com. All Rights Reserved. Design by HTML Codex