Migrating from Get-AzureADUserManager to Get-MgUserManager

With the deprecation of the AzureAD module, Microsoft recommends transitioning to the Microsoft Graph PowerShell SDK for managing Microsoft 365 environments. One of the commonly used cmdlets in user management is Get-AzureADUserManager, which retrieves a user's manager based on the Azure AD organizational hierarchy.

In this article, we’ll guide you through how to migrate to the modern Graph-based alternative: Get-MgUserManager. You’ll learn what’s different, how it improves visibility, and how to scale it across multiple users.


What You Did Previously with Get-AzureADUserManager

In the AzureAD module, you used the following to retrieve the manager of a specific user:

Get-AzureADUserManager -ObjectId "john.doe@yourdomain.com"

This would return a basic directory object representing the user’s manager. It worked fine, but had limitations when it came to extending or combining with other Graph services.


What You Should Do Now with Get-MgUserManager

The Graph equivalent is the Get-MgUserManager cmdlet, which gives you more consistent object output and integrates seamlessly with broader Graph-based queries and automation.


Retrieve the Manager for a Specific User

Get-MgUserManager -UserId "john.doe@yourdomain.com"

Or using the GUID of the user:

Get-MgUserManager -UserId "1234abcd-5678-efgh-9101-ijklmnopqrst"

Here’s how you can use it in bulk for all users in a department, like "Sales":

$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
    }
}
                                            

This approach is ideal for reporting, hierarchy validation, and org-chart visualizations.


What’s Different with Get-MgUserManager?


Old (Get-AzureADUserManager) New (Get-MgUserManager)
Parameter: -ObjectId Parameter: -UserId (accepts UPN or GUID)
Basic directory object returned Returns rich Microsoft Graph user object
Part of AzureAD module (deprecated) Part of Microsoft.Graph.Users module
Not extensible for bulk use Easily scriptable and extendable for reporting
Limited integration Integrates with other Graph cmdlets seamlessly

Conclusion

Switching from Get-AzureADUserManager to Get-MgUserManager is essential if you're looking to modernize your scripts, improve accuracy, and support scalable reporting. Whether you’re pulling a manager for a single user or looping through an entire department, Graph’s structured output and deep integration provide a major upgrade over the legacy AzureAD module.

Visit M365Corner.com for ready-to-use free Microsoft Graph PowerShell tools and step-by-step migration guides built for Microsoft 365 administrators.


Permission Required

Example:


                                


                                


                                

© Your Site Name. All Rights Reserved. Design by HTML Codex