Others

How to Export Microsoft 365 Mailboxes Inactive for 90 Days

Kushani NimanthikaKushani Nimanthika Nov 2, 2026 870 views

Question details

The user needs to generate and export a CSV report containing Microsoft 365 mailboxes that have not been logged into for more than 90 days.

How to Export Microsoft 365 Mailboxes Inactive for 90 Days
Product
Microsoft 365
Device & OS
not provided
Scenario
Administering Microsoft 365 environments and attempting to track unused licenses or inactive user accounts via PowerShell.
Observed behavior
The current PowerShell pipeline fails to generate a CSV file and throws an error stating that the mailbox name is not unique.
Before you start

Ensure you have the Exchange Online PowerShell module installed and that you are connected using an administrator account with the necessary permissions.

Solution 1Recommended

Use UserPrincipalName in Exchange Online PowerShell

Resolve the unique identifier error by passing the UserPrincipalName to Get-MailboxStatistics, then filter and export the results to a CSV file.

When retrieving mailbox statistics, using the default identity can sometimes result in conflicts if multiple mailboxes share similar display names or aliases. Using the UserPrincipalName guarantees a unique identifier for each account, allowing the pipeline to process successfully.

1
Connect to Exchange Online

Open PowerShell as an administrator and run the command 'Connect-ExchangeOnline' to authenticate with your Microsoft 365 admin credentials.

2
Run the Export Script

Execute the following command to retrieve, filter, and export the mailboxes: Get-Mailbox -ResultSize Unlimited | ForEach-Object { Get-MailboxStatistics -Identity $_.UserPrincipalName } | Where-Object {$_.LastLogonTime -lt (Get-Date).AddDays(-90)} | Select-Object DisplayName,LastLogonTime,MailboxTypeDetail | Export-Csv 'C:\InactiveMailboxes.csv' -NoTypeInformation

3
Review the Exported CSV

Navigate to your C: drive and open the 'InactiveMailboxes.csv' file using your preferred spreadsheet application to review the inactive accounts.

Use UserPrincipalName in Exchange Online PowerShell
Execution Time: If your organization has thousands of mailboxes, retrieving statistics for all of them may take several minutes to complete. Do not close the PowerShell window.
Free Microsoft Office alternative

Easily Analyze Your Exported CSV Reports with WPS Office

While Microsoft 365 requires complex PowerShell scripts to manage mailboxes, you need a reliable spreadsheet tool to view the results. WPS Office is a free, lightweight suite that makes filtering and analyzing your exported administrative CSV reports incredibly easy.

  1. 1. Download WPS Office: Visit the official WPS website to download and install the free office suite.
  2. 2. Open WPS Spreadsheet: Launch the application and select the Spreadsheets module.
  3. 3. Analyze the CSV Report: Open your exported 'InactiveMailboxes.csv' file to easily view, format, and filter your Microsoft 365 data.
Fully compatible with Microsoft Excel CSV, XLSX, and XLS file formats.Lightweight design ensures incredibly fast loading of large, data-heavy administrative reports.Familiar and intuitive user interface allows for a seamless migration with zero learning curve.Powerful data sorting and filtering tools to quickly isolate specific inactive users.Completely free alternative to expensive premium office subscriptions.
microsoft office alternative - wps office

Frequently Asked Questions

Why does Get-MailboxStatistics return a 'mailbox name is not unique' error?

This error occurs when the script relies on standard display names or aliases, which might be duplicated across your organization. By explicitly calling the UserPrincipalName ($_.UserPrincipalName), you provide a universally unique identifier that prevents this conflict.

Do I need special permissions to run these PowerShell commands?

Yes, you must be assigned appropriate administrative roles in Microsoft 365, such as Organization Management or Recipient Management, to run Get-Mailbox and Get-MailboxStatistics.

Can I change the inactivity threshold from 90 days to something else?

Absolutely. In the PowerShell script provided, simply change the '-90' in the AddDays(-90) method to your desired number of days (for example, -30 for 30 days of inactivity).

What is the best way to open the exported CSV file?

You can open the generated CSV file using a dedicated spreadsheet application like WPS Office Spreadsheets or Microsoft Excel. This allows you to adjust column widths, sort by LastLogonTime, and format the data properly.