Export Microsoft 365 Email Activity Report with PowerShell
Question details
The user needs to create a scheduled PowerShell script to export Microsoft 365 Email Activity reports to a CSV file and clarify role requirements.

- Product
- Microsoft 365
- Device & OS
- not provided
- Scenario
- Automating Microsoft 365 administration tasks to track user principal names, activity dates, and message counts.
- Observed behavior
- Seeking a script solution and validation on whether Global Reader and Report Reader roles provide sufficient permissions for API access.
Before running Microsoft 365 PowerShell scripts, ensure you have the Microsoft Graph PowerShell SDK installed and have verified your tenant admin or reporting credentials.
Use Microsoft Graph PowerShell to Export Email Activity
The modern and recommended approach to accessing Microsoft 365 usage reports is through the Microsoft Graph PowerShell SDK.
Microsoft provides the Graph API to programmatically access usage and activity reports. You can use the Microsoft.Graph module in PowerShell to authenticate and pull this data into a structured CSV file.
Open PowerShell as an administrator and run 'Install-Module Microsoft.Graph' to install the necessary SDK.
Run 'Connect-MgGraph -Scopes "Reports.Read.All"' to authenticate. Your Global Reader or Report Reader account must be used here.
Use the 'Get-MgReportEmailActivityUserDetail' cmdlet to retrieve the email activity metrics, specifying the desired reporting period.
Pipe the output of your query to the export command: '... | Export-Csv -Path "C:\EmailActivityReport.csv" -NoTypeInformation'. This generates the file containing user principal names and message counts.

Consult the Microsoft PowerShell Community for Advanced Scheduling
If you need to schedule complex scripts securely or need advanced filtering, the Microsoft PowerShell community can provide specialized advice.
Edit Your Exported CSV Reports with WPS Office
While PowerShell handles the extraction of Microsoft 365 data, you need a reliable spreadsheet tool to analyze the exported CSV files. WPS Office is a highly compatible, free alternative to Microsoft Office that effortlessly handles large datasets, CSV formatting, and data visualization.
- 1. Launch WPS Spreadsheet: Open WPS Office on your computer and select the Spreadsheet application.
- 2. Open your CSV file: Click 'Open' and browse to the location where your PowerShell script saved the Email Activity CSV report.
- 3. Analyze the metrics: Use the Data tab tools to filter, sort, and create charts based on user principal names and message counts.

Frequently Asked Questions
Are the Global Reader and Report Reader roles sufficient to export Microsoft 365 usage reports?
Yes, the Report Reader role allows a user to view usage data reports in the Microsoft 365 admin center and access them programmatically via the Microsoft Graph API without needing full admin privileges. The Global Reader role also inherits this read-only access.
How can I schedule a PowerShell script to run automatically?
You can schedule a PowerShell script using the Windows Task Scheduler. Create a new task, set the trigger for your desired daily or weekly schedule, and set the action to start a program. Use 'powershell.exe' as the program and add '-File "C:\Path\To\YourScript.ps1"' in the arguments field.
Why does my exported CSV report contain formatting issues or strange characters?
This often occurs due to encoding mismatches during the export process. When using the Export-Csv cmdlet in PowerShell, append the '-Encoding UTF8' parameter to ensure all text and special characters are preserved correctly.




