--- title: "Generate an Organization Tree Map and Entity List via Microsoft Graph" slug: "dex-wf-org-tree-map-entity-list" updated: 2026-11-30T16:14:51Z published: 2026-11-30T16:14:51Z canonical: "documentation.sysaid.com/dex-wf-org-tree-map-entity-list" --- > ## Documentation Index > Fetch the complete documentation index at: https://documentation.sysaid.com/llms.txt > Use this file to discover all available pages before exploring further. # Generate an Organization Tree Map and Entity List via Microsoft Graph Build a complete hierarchical org chart and entity inventory from your Microsoft 365 tenant using Graph API, manager relationships, departments, and groups. **Complexity:** Intermediate. **Impact:** read-only + reporting + governance + audit-ready. ## Why use this workflow Understanding an organization's structure is foundational to governance, onboarding, access reviews, and communications planning. While Microsoft 365 stores rich organizational data: user profiles, manager relationships, departments, and group memberships: there is no built-in admin view that presents a complete hierarchical tree alongside an entity inventory. This workflow walks through generating that view programmatically by combining data from `/users`, `/users/{id}/manager`, and `/groups` in Microsoft Graph. The result is a visual reporting-line tree plus a consolidated list of departments and groups that exist in the tenant. ### When to run this workflow - During annual access reviews or governance audits - Before a reorganization, merger, or acquisition - When onboarding new HR or IT leadership who need to understand the org - As part of a readiness assessment for Conditional Access, Sensitivity Labels, or lifecycle workflows that depend on department/manager attributes - To detect data quality issues (missing managers, missing departments, orphaned users) ## Expected outcomes - A hierarchical ASCII/text tree showing every reporting chain in the tenant, starting from users with no manager (CEOs, contractors, service accounts) - A complete list of departments with employee counts per department - An inventory of all Microsoft 365 Groups and Security Groups, including descriptions and type - Summary statistics: total users, top-level managers, department count, group count - A downloadable `organization-map.txt` report suitable for sharing with HR, leadership, or auditors You can feed the same data into Visio, Mermaid diagrams, or BI tools for richer visualizations. ## Risks and considerations ### Data accuracy - The tree is only as good as the `manager` attribute in Entra ID. Many tenants have incomplete manager data: users without managers will appear as roots, producing a flat-looking tree. - Users with `department` left blank will be grouped under "No Department". - Guest users (`userType = Guest`) are included by default. Filter them out if you only want employees. ### Performance and throttling - Fetching manager relationships requires one API call per user. For tenants with 10,000+ users, batch requests or use `$expand=manager` to reduce call volume. - Microsoft Graph throttles at roughly 10,000 requests / 10 minutes per app per tenant. Implement retry with exponential backoff on HTTP 429. ### Privacy and handling - The output contains PII (names, titles, email addresses, reporting lines). Treat the file as confidential and store it only in approved locations. - Do not email the raw report externally: it can reveal sensitive org structure to attackers for spear-phishing. ### Do not - Do not mutate user or group data from this workflow: it is read-only by design. - Do not rely on the tree for compliance attestations without validating manager data against HRIS first. ## Required permissions | Permission | Why it's needed | | --- | --- | | User.Read.All | Enumerate all users and read profile properties (displayName, jobTitle, department, mail). | | Directory.Read.All | Read manager relationships via /users/{id}/manager to build the reporting hierarchy. | | Group.Read.All | Enumerate Microsoft 365 Groups and Security Groups as organizational entities. | | Organization.Read.All | Retrieve tenant organization details (display name, verified domains). | ## Ask Dex Paste the prompt into a Dex conversation. ### Prompt for IT admins ``` Generate an organization tree map and entity list for our Microsoft 365 tenant. Include the full reporting hierarchy (based on manager relationships), a breakdown of departments with employee counts, and an inventory of all Microsoft 365 and Security Groups. Deliver the output as a downloadable text report. ``` ### How an end user can ask Dex ``` Can you show me our company's org chart - who reports to who, what departments we have, and what Teams or groups exist? ``` ## Manual steps (admin center) There is no single GUI that produces a complete tree map, but you can assemble equivalent information across three admin surfaces. This approach is suitable for small tenants (<50 users) or spot-checks. ### Step 1: Export the user list from Microsoft 365 admin center 1. Sign in to https://admin.microsoft.com as a Global Reader or User Admin. 2. Go to **Users** > **Active users**. 3. Click **Export users** in the toolbar. A CSV containing display name, UPN, licenses, and basic profile data will download. ### Step 2: Capture manager/department detail from Entra ID 1. Go to https://entra.microsoft.com > **Identity** > **Users** > **All users**. 2. Click **Download users** > **Start**. The resulting CSV includes `department`, `jobTitle`, and `city`, but *not* manager. Manager must be read per-user: 3. For each user you care about, open the user blade > **Job info** tab and note the **Manager** field. ### Step 3: Inventory groups 1. In Entra, go to **Groups** > **All groups**. 2. Click **Download groups** > **Start**. The CSV lists every group with its type (Security / Microsoft 365), mail-enabled flag, and description. ### Step 4: Build the tree 1. Open the user CSV in Excel. Add a *Manager* column populated from Step 2. 2. Use a PivotTable or a tool like **Visio** > **Create from Data** > **Organization Chart Wizard**, pointing at the CSV with *Name* and *Reports to* columns. Visio will render a hierarchy automatically. *Because manager data is read one user at a time in the GUI, the API or PowerShell approach below is strongly recommended for tenants with more than a handful of users.* ## Microsoft Graph API Three Graph endpoints are combined to produce the tree map and entity list. ### 1. Read tenant organization details ``` GET https://graph.microsoft.com/v1.0/organization ``` Returns tenant display name and verified domains. Useful as the report header. ### 2. Enumerate users with paging ``` GET https://graph.microsoft.com/v1.0/users?$select=id,displayName,jobTitle,department,mail,userPrincipalName&$top=999 ``` Follow the `@odata.nextLink` until it is absent. Keep `$select` narrow to minimize payload. ### 3. Resolve manager per user The list endpoint does not return `manager` in the default projection. Either expand it or call per-user: ``` // Option A: expand on the list call GET /v1.0/users?$select=id,displayName,department,jobTitle&$expand=manager($select=id,displayName) // Option B: per-user lookup GET /v1.0/users/{user-id}/manager?$select=id,displayName ``` A **404** on the per-user manager call means the user has no manager assigned: treat them as a tree root. Do *not* treat 404 as an error. ### 4. Enumerate groups ``` GET /v1.0/groups?$select=id,displayName,description,groupTypes,mailEnabled,securityEnabled&$top=999 ``` Groups where `groupTypes` contains `Unified` are Microsoft 365 Groups; otherwise they are Security or Distribution groups. ### Sample response fragment ``` {  "value": [    {      "id": "2f2d3187-5fad-4d73-a9f5-3c356e68a038",      "displayName": "Patti Fernandez",      "jobTitle": "Chief Executive Officer",      "department": "Executive"    }  ] } ``` ### Throttling On HTTP 429, honor the `Retry-After` header. For large tenants, use [JSON batching](https://learn.microsoft.com/graph/json-batching) (20 requests per batch) to fetch manager relationships more efficiently. ## PowerShell This workflow uses the official `Microsoft.Graph` module. It authenticates interactively, pages through all users, resolves managers, collects groups, and writes a formatted `organization-map.txt`. ### Prerequisites - PowerShell 7+ (recommended) or Windows PowerShell 5.1 - `Install-Module Microsoft.Graph -Scope CurrentUser` - A Global Reader (or higher) account for the target tenant ### How it works 1. `Connect-MgGraph` prompts for consent on the four required scopes. 2. `Get-MgUser -All -ExpandProperty Manager` fetches every user in a single paged call with the manager attribute expanded: avoiding one-call-per-user. 3. The script builds a hashtable keyed by user ID, attaches children to their manager, and identifies roots (users with no manager). 4. A recursive `Write-Tree` function emits the ASCII tree with `├──`, `└──`, and indentation. 5. `Get-MgGroup -All` pulls the group inventory. 6. Everything is written to `organization-map.txt` in the current directory. ### Running the script ``` .\Generate-OrgTreeMap.ps1 -OutputPath "C:\Reports\org-map.txt" ``` Use `-IncludeGuests:$false` (the default) to exclude external guests from the tree.