Create a list of inactive Exchange mailboxes

Last reviewed on December 5, 2013

This question came from an Office 365 Exchange Online administrator. The Office 365 Administration page shows they have some inactive users but it doesn't list their names.

When I log into the Office365 administrative dashboard, it shows me how many inactive users there are, but it doesn't tell me who is inactive. How can I get this information?

Inactive users in Office 365 Exchange Online

As you've discovered, Office 365 doesn't include the names of the inactive mailboxes, but you can use PowerShell to get a list of all users and their last login time.

Get-mailbox -resultsize unlimited| Get-MailboxStatistics | select displayname, lastlogontime

If you have a large number of mailboxes, you can send the results to a CSV file and open it in Excel to sort by the date field. To output the results to a CSV file, add Export-CSV and the file path.

Get-mailbox -resultsize unlimited| Get-MailboxStatistics | select displayname, lastlogontime | Export-Csv C:\Files\test.csv

Use PowerShell to get a list in users and the last logon time

Tip: If you want to save the file in the path the used in PowerShell, usually C:\Users\Username, you only need to add the folders and file name, as seen in the screenshot above, where the CSV file was saved to C:\Users\Diane\Documents.

Step-by-step instructions

  1. Open PowerShell using Run as Administrator. Run the following cmdlet to bring up the log in dialog. Enter the Exchange server's administrator username and password. Note, you must have administrator rights to the server to use this.
  2. $LiveCred = Get-Credential

  3. Next, run this cmdlet:
  4. $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection

  5. And then run this cmdlet:
  6. Import-PSSession $Session

  7. Now you're ready to get the list of users and their last logon time. If you want to output the results to a CSV file, add the Export-CSV command.
  8. Get-mailbox -resultsize unlimited| Get-MailboxStatistics | select displayname, lastlogontime | Export-Csv C:\Files\test.csv

Written by

Diane Poremsky
A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

If the Post Coment button disappears, press your Tab key.