Bulk User Report to Excel
Export all Office 365 users with department, title, location, and license info to an Excel workbook on SharePoint for auditing.
Provided as-is, without warranty of any kind. Review and test each pattern in a non-production environment before deploying it to live automations. See our Terms.
Overview
This flow exports all Office 365 users with their profile information (display name, email, department, job title, office location, city, account status, and UPN) to an Excel workbook on SharePoint. It runs on a weekly schedule and sends a completion notification email with the user count and report link.
Use Case
IT administrators and HR teams need a current directory of all Office 365 users for auditing, onboarding planning, license reviews, and organizational reporting. This flow automates the export so the Excel report is always up-to-date without manual effort.
Flow Architecture
Recurrence - Weekly Monday 8AM
RecurrenceFires every Monday at 8:00 AM Eastern.
Initialize varSiteURL
Initialize variableReads SharePoint site URL from the flowlibs_SharePointSiteURL env var.
Initialize varDriveID
Initialize variableReads the Graph drive ID for the target document library from env var.
Initialize varExcelFile
Initialize variableReads the Excel workbook file path from env var.
Initialize varExcelTable
Initialize variableReads the Excel table name from env var.
Initialize varRecipientEmail
Initialize variableReads the notification recipient email from env var.
Initialize varUserCount
Initialize variableInteger counter initialized to 0; tracks how many users are written to Excel.
Search All Users
Office 365 Users - SearchUserV2Retrieves up to 999 users from the directory.
Loop Through Each User
Apply to each (sequential)For each user returned by the search: write a row to the Excel table and increment the user counter. Sub-actions: Add User Row to Excel (Excel Online AddRowV2) writes display name, email, department, job title, office location, city, account status, and UPN to the table; Increment User Counter increases varUserCount by 1.
Send Report Completion Email
Environment Variables
| Schema name | Type | Default | Description |
|---|---|---|---|
| flowlibs_SharePointSiteURL | String | https://your-tenant.sharepoint.com | Root SharePoint site URL where the report workbook lives. |
| flowlibs_UserReportDriveID | String | <configure> | Graph API drive ID for the Shared Documents library. Get it via Graph Explorer: GET /sites/{site-id}/drives. |
| flowlibs_UserReportExcelFile | String | /Shared Documents/FlowLibs - User Report.xlsx | Server-relative path to the Excel workbook that receives the rows. |
| flowlibs_UserReportExcelTable | String | UserReport | Name of the Excel table inside the workbook that holds the user rows. |
| flowlibs_UserReportRecipientEmail | String | admin@your-tenant.onmicrosoft.com | Email address (or semicolon-separated list) that receives the completion notification. |
Connectors & Connections
| Connector | API name | Actions used |
|---|---|---|
| Office 365 Users | shared_office365users | SearchUserV2 (retrieve up to 999 users from the directory) |
| Excel Online (Business) | shared_excelonlinebusiness | AddRowV2 (write a row per user to the UserReport table) |
| Office 365 Outlook | shared_office365 | SendEmailV2 (send the completion email with the user count and report link) |
Note — All connections are referenced as solution connection references; the flow is portable between environments as long as a connection is mapped at import time.
Customization Guide
Almost every realistic variant of this flow can be implemented by changing environment variable values. A few cases require small edits inside the flow definition — those are called out explicitly below.
- Change the schedule
- Edit the Recurrence trigger to adjust frequency (daily, monthly) or the time of day to match when you need fresh data.
- Filter users
- Add a Condition or Filter Array after Search All Users to only export specific departments, office locations, or enabled accounts.
- Add columns
- Update the Excel workbook table with new columns, then add matching fields to the item object on the Add User Row to Excel action.
- Change report location
- Update flowlibs_UserReportDriveID and flowlibs_UserReportExcelFile to point to a different document library or workbook.
- Clear previous data each run
- Add a Delete All Rows action before the loop to wipe the table on each run (or keep appending for historical tracking).
- Multiple recipients
- Set flowlibs_UserReportRecipientEmail to a semicolon-separated list of addresses to fan the notification out to a wider audience.
Key Expressions
The flow is intentionally light on Power Fx / WDL gymnastics — the heaviest expressions are the branch-name concatenation and the approval outcome check. They are listed below in the order they appear in the flow.
EXPR.01Null-safe field access
Wrapping each user property in coalesce prevents null values from breaking the Excel row insert.
EXPR.02Report link in email body
Concatenates the SharePoint site URL with the workbook path to produce a clickable link to the report.
EXPR.03User count in email body
Inlines the final exported-user count into the completion email.
Comments
Sign in to join the conversation.
Sign inNo comments yet. Be the first to share your experience with this flow.