How to get an AD user's manager

Whether you need to find a user's manager, get manager contact details, or export comprehensive reports, the Get-ADUser PowerShell cmdlet is a powerful tool. This article demonstrates how to use this cmdlet to retrieve manager information, explores common use cases, and discusses its limitations. We'll also show you how this task can be streamlined using the various AD user reports available in ADManager Plus, a comprehensive AD reporting tool.

Getting a user's manager: PowerShell vs. ADManager Plus

The following table compares how you can get an AD user's manager using their display name in using PowerShell versus ADManager Plus.

Windows PowerShell

Before you start, ensure you have:

  • The Active Directory PowerShell Module installed.
  • The correct PowerShell Execution Policy is configured.
  • The account you are using has read permissions for the AD domain you intend to query.

To get a user's manager using PowerShell, first you need to get the user object, then use the Manager property to retrieve the manager's object.

Get-ADUser -Identity "John" -Properties manager
ADManager Plus

To find an AD user's manager using ADManager Plus:

  1. Log in to ADManager Plus.
  2. Navigate to Reports > User Reports > General Reports > All Users.
  3. Select the Domain and OU and click Generate.
  4. Click Add/Remove columns to add a Manager column to the results.
  5. Use the Export As option to export the report in any of the following format-CSV, PDF, XLSX, HTML and CSVDE.

Examples and use cases

Here are some of the most common scenarios you'll encounter when querying for a user's manager:

Example 1: Get a user's manager's display name

By default, the manager property of a user object returns the manager's distinguished name (DN), which isn't very readable. To get the manager's actual name, you need to perform another query using the Get-ADUser cmdlet.

# Get the user and their manager's DN
$user = Get-ADUser -Identity "jdoe" -Properties Manager
# Check if the manager property is populated
if ($user.Manager) {
# Get the manager object using the DN
$manager = Get-ADUser -Identity $user.Manager -Properties DisplayName
Write-Host "The manager for $($user.Name) is $($manager.DisplayName)."
} else {
Write-Host "$($user.Name) does not have a manager assigned."
}

Example 2: Get a user's manager's email address

A common IT request is to get the manager's email address for notification or approval workflows. This requires fetching the mail property from the manager's user object.

$user = Get-ADUser -Identity "John" -Properties manager
if ($user.Manager)
{
# Get the manager and select their email address property
$manager = Get-ADUser -Identity $user.manager -Properties mail
Write-Host "The email address for the manager of $($user.Name) is $($manager.mail)."
} else {
Write-Host"$($user.Name) does not have a manager assigned."
}

Example 3: Export a list of users and their managers to CSV

To generate a report for multiple users, you can combine these commands and export the output to a CSV file.

Get-ADUser -Filter * -Properties Manager | ForEach-Object {
$userObject = $_
$managerName = "" # Default to empty string
if ($userObject.Manager) {
# Get the manager's DisplayName
$manager = Get-ADUser -Identity $userObject.Manager -Properties DisplayName
$managerName = $manager.DisplayName
}
# Create a custom object with the desired properties
[PSCustomObject]@{
UserName = $userObject.Name
sAMAccountName = $userObject.sAMAccountName
Manager = $managerName
}
} | Export-Csv -Path "C:\Reports\UsersAndManagers.csv" -NoTypeInformation

Example 4: Get all users under a specific manager

You can use the Filter parameter to find all users where the manager property is equal to the manager's distinguished name.

$manager = Get-ADUser "themanager"
Get-ADUser -Filter "Manager -eq '$($manager.DistinguishedName)'"

Limitations of using PowerShell to get users' managers

While PowerShell can be used to retrieve user reports, it comes with several limitations:

  • Complex syntax: Retrieving a simple piece of information, like a manager's name, requires multiple commands and handling of object properties.
  • Error handling: Scripts need additional logic to handle cases where a user has no manager, or if a specified user doesn't exist, to avoid errors.
  • Performance challenges: When processing thousands of users, repeatedly querying manager objects can be slow and resource-intensive.

Highlights of using ADManager Plus for getting AD user's manager

ADManager Plus provides a simple and efficient alternative to PowerShell scripting for AD reporting.

  • GUI-based and script-free: Generate detailed reports, including user and manager details, with a few clicks in an intuitive interface.
  • Prebuilt AD reports: Generate from over 200 prebuilt reports on AD to get instant visibility on AD objects.
  • Automated and scheduled reporting: Create manager-based reports and have them run automatically. Additionally, email results to stakeholders, ensuring up-to-date organizational visibility.

Get AD users' managers using ADManager Plus

FAQs

The manager property on the user object will be empty. Your script should include an if statement to check if the property exists before trying to use it, which prevents errors.

You can use the Set-ADUser cmdlet to assign or change a manager. You need the identity of the user to modify and the identity of the new manager as well. Here's a sample script:

Set-ADUser -Identity "John" -Manager "Jake"

This requires a recursive PowerShell function that repeatedly calls Get-ADUser for each manager until it reaches a user with no manager assigned.

The one-stop solution to Active Directory Management and Reporting
Email Download Link