How to Export Microsoft 365 User and Manager Details to CSV
Question details
An administrator needs to generate a CSV report containing manager information for all licensed Microsoft 365 users.

- Product
- Microsoft 365
- Device & OS
- not provided
- Scenario
- Generating an administrative hierarchy report containing licensed users and their assigned managers in the organization.
- Observed behavior
- Administrators need a programmatic method to retrieve user details, query their respective manager's information, and compile the combined data into a CSV format without throwing errors for unassigned fields.
Ensure you have the Microsoft Graph PowerShell module installed and that your administrator account has the Directory.Read.All permission in Microsoft Entra ID.
Use Microsoft Graph PowerShell (Recommended)
Microsoft Graph PowerShell is the modern, supported standard for querying Microsoft Entra ID data, replacing legacy AzureAD cmdlets.
This method queries the Microsoft Graph API to securely retrieve licensed users and their corresponding managers, compiling them into a single report.
Open your PowerShell console as an administrator and run `Connect-MgGraph -Scopes 'User.Read.All'` to authenticate with your tenant.
Fetch active licensed users by running a query like `Get-MgUser -Filter "assignedLicenses/$count ge 1" -ConsistencyLevel eventual -All`.
Set up a loop to iterate through each user. Inside the loop, use `Get-MgUserManager -UserId $user.Id` to retrieve the manager's display name and email address.
Create a custom PSObject containing the user's name, email, department, and their manager's details. Finally, pipe the collected objects to `Export-Csv -Path 'C:\Reports\UserManagers.csv' -NoTypeInformation`.

Use Legacy AzureAD Cmdlets
If you are running an older script environment, you can use the classic AzureAD module, though it is currently retired.
Easily Open and Analyze Your CSV Reports with WPS Office
After exporting your Microsoft 365 user and manager details via PowerShell, you will need a robust spreadsheet tool to analyze the data. WPS Office is a free, lightweight, and highly compatible alternative to Microsoft Office, offering familiar tools for data analysis without the premium subscription costs.
- 1. Launch WPS Spreadsheets: Open WPS Office on your desktop and click on the Spreadsheets module.
- 2. Open the CSV File: Navigate to Menu > Open, locate the folder where your PowerShell script saved the 'UserManagers.csv' report, and select it.
- 3. Analyze the Data: Use the Data tab to apply filters, sort by department, or format the manager hierarchy columns for easy reading and presentation.

Frequently Asked Questions
Why is the manager field blank or causing errors for some users?
The manager property is not automatically populated in Microsoft 365; it must be manually assigned in Microsoft Entra ID or synchronized from an on-premises Active Directory. If a user has no assigned manager, the Graph API will return an error unless you handle it with a Try-Catch block in your script.
Can I include the user's department in the same CSV?
Yes. When querying the user object, ensure you select the 'Department' property alongside the DisplayName and UserPrincipalName. You can then append it to your custom PowerShell object before exporting.
Is the AzureAD PowerShell module still supported?
No, Microsoft has officially retired the AzureAD, AzureADPreview, and MSOnline modules. It is strongly recommended to update all automation scripts to use Microsoft Graph PowerShell to ensure ongoing functionality.




