• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Create a list of inactive Exchange mailboxes

Slipstick Systems

› Exchange Server › Cmdlets › Create a list of inactive Exchange mailboxes

Last reviewed on January 25, 2017     28 Comments

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.
    $LiveCred = Get-Credential
  2. Next, run this cmdlet:
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
  3. And then run this cmdlet:
    Import-PSSession $Session
  4. 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.
  5. Get-mailbox -resultsize unlimited| Get-MailboxStatistics | select displayname, lastlogontime | Export-Csv C:\Files\test.csv
Create a list of inactive Exchange mailboxes was last modified: January 25th, 2017 by Diane Poremsky
Post Views: 390

Related Posts:

  • Use Powershell to configure Automatic Replies
  • Find Users with Send On Behalf Permission
  • Convert an Exchange Mailbox to a Shared Mailbox
  • Enable Office 365 Exchange Online Archive

About 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.

Comments

  1. ShandyT says

    January 15, 2022 at 12:18 pm

    Is there as way to get a csv list all Shared mailboxes that have not been used for a long time?
    Tried it through Exchange Compliance Management but I need a hard copy of the listed mailboxes to show HoD's.

    Reply
    • Diane Poremsky says

      January 17, 2022 at 11:22 pm

      You can use PowerShell. But... if someone has the shared mailbox in their profile but are not actually using it, the last access time will be current.
      $Result=@()
      $mailboxes = Get-Mailbox -RecipientTypeDetails SharedMailbox -ResultSize Unlimited
      $totalmbox = $mailboxes.Count
      $i = 1
      $mailboxes | ForEach-Object {
      $i++
      $mbox = $_
      $mailboxstats = Get-MailboxStatistics -Identity $mbox.UserPrincipalName | Select LastLogonTime
      if ($mailboxstats.LastLogonTime -eq $null){
      $lt = "Never Logged In"
      }else{
      $lt = $mailboxstats.LastLogonTime }

      Write-Progress -activity "Processing $mbox" -status "$i out of $totalmbox completed"

      $Result += New-Object PSObject -property @{
      Name = $mbox.DisplayName
      UserPrincipalName = $mbox.UserPrincipalName
      LastLogonTime = $lt }
      }

      $Result | Export-CSV "C:\LastLogon-Info.csv" -NoTypeInformation -Encoding UTF8

      Reply
  2. Arsal says

    May 15, 2020 at 3:57 am

    Get-mailbox -resultsize unlimited| Get-MailboxStatistics | select displayname, lastlogontime
    This command returns list of mailboxes with display name and last logon time but I also want to get PrimarySMTPAddress of mailboxes which is part of Get-mailbox cmdlt but not a part of Get-MailboxStatistics. Anyone know ho to achive that?

    Reply
  3. Dave says

    August 15, 2017 at 2:23 pm

    So can we trust LastLogonTime? If it's null, does that really, really, REALLY mean the user has never used their account? I'm needing to clean out the unused accounts in our Office365 tenant (probably a few thousand), and I don't want to nuke accounts that may still be in use. If LastLogonTime is null, that means they've never logged-in, right? No gotchas, no exceptions?

    Reply
    • Diane Poremsky says

      August 15, 2017 at 5:25 pm

      Yeah, it would mean the user never logged in. If it is a shared mailbox, the date is the last time someone with permission to the mailbox accessed it.

      Reply
  4. Dennis says

    June 5, 2017 at 4:16 am

    Why use Excel?
    Try piping to Out-GridView or just pipe to sort-object

    After all we are talking PowerShell :)

    Reply
    • Diane Poremsky says

      June 5, 2017 at 8:09 am

      Because some people might want a csv file to review later...

      Reply
  5. Johan says

    January 8, 2017 at 4:50 pm

    Hello, how can i create a report with all SMTP alliases of an account and count number of messages received on that account last 3 months? So that we can remove unused alliasses from an account.

    Reply
    • Diane Poremsky says

      January 9, 2017 at 12:19 am

      You'll need to get all addresses on the account then search the mailbox. You can do this using VBA but i don't have a macro handy that does it. If you only need to check a few addresses, you could set up mail flow rules and either tag the subject lines (so they are easier to find) or forward to another address to monitor. But, this would only work going forward.

      Reply
  6. jesus says

    May 24, 2016 at 11:49 am

    it is possible to change to change the UPN for another. I have the email in a csv file. im using o365

    Reply
    • Diane Poremsky says

      May 24, 2016 at 3:12 pm

      If you have the message header and it's editable, yes, but what are you trying to accomplish? There might be a better way.

      Reply
      • jesus says

        May 24, 2016 at 3:36 pm

        for exaple change jcarlos.1234@mydomain.com to 1234@mydomain.com

      • Diane Poremsky says

        August 18, 2016 at 11:38 am

        This powershell will remove current addresses, replace them with the addresses in the cmdlet and set one as default.
        Set-Mailbox Username -EmailAddresses SMTP:alias@domain.com,smtp:alias@domain.onmicrosoft.com,smtp:otheralias@domain.com

  7. Ron Walters says

    April 14, 2016 at 4:35 pm

    Need some help here.. have been tasked with finding a way to be alerted when emails reach 100 unopened emails .. any ideas ?

    Reply
    • Diane Poremsky says

      April 14, 2016 at 4:45 pm

      100 in your own inbox or across the entire exchange org?

      While we can get a running total of your new mail as it arrives, counting only unread messages means we need to check the inbox every so often, just in case you read messages. It can be a little more intensive, especially if the inbox is huge as outlook needs to check each message and see if it's read.

      Getting a count for all users on the server is much more difficult.

      Reply
  8. Greg Lamb says

    July 5, 2015 at 7:05 pm

    Is LastLogin a good indication of actual usage though? If staff have the mailbox attached to their Outlook install wouldn't it login every time they use Outlook and therefore not give a good enough indication of when the mailbox was actually used? Something along the lines of when the last email was received would be good??

    Reply
    • Diane Poremsky says

      July 6, 2015 at 12:57 am

      Outlook will log in every time the mailbox is opened, so will various services. I no longer have an Exchange 2010 server running to check the results of the Get-mailbox command, but I'm pretty sure it include the last time the mailbox logged in as itself.

      I don't think you'll be able to easily get a good value for 'last actively used' - a new message doesn't necessarily mean they read it. Last sent message would be better, but that also doesn't prove they didn't send a message recently. I don't have any scripts that get this information (their might be some in the TechNet gallery) and you'll need to have permission to read the mailbox.

      Reply
  9. Rup Singh says

    May 19, 2015 at 3:21 pm

    Hi, we are running Exchange 2010 and I want to know which script to run on our mailbox server to tell me which mailboxes are inactive/not in use for x period of time - ie. 365 days.
    We have a number of shared mailboxes and I ran/downloaded the script from https://gallery.technet.microsoft.com/scriptcenter/List-Inactive-Mailboxes-on-1ac82ddf
    and this tells me my shared mailboxes have not sent any emails in x # of days, but that is incorrect as the shared mailboxes are in use daily. ie our helpdesk email account.

    Reply
    • Diane Poremsky says

      June 30, 2015 at 6:32 pm

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

      Office 365 has the stalemailbox cmdlet is available in 2010 - but this reports in active mailboxes.
      Get-StaleMailboxDetailReport | Sort username -Unique | SELECT TenantName, UserName, WindowsLiveID, LastLogin, DaysInactive

      Reply
  10. Jeff says

    October 17, 2014 at 8:12 am

    Don...the cmdlet won't work if you are running it in powershell. It must be run from the Exchange Management Shell

    Reply
  11. Don says

    August 12, 2014 at 6:36 pm

    The term 'Get-mailbox' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
    spelling of the name, or if a path was included, verify that the path is correct and try again.
    At line:1 char:12
    + Get-mailbox <<<< -resultsize unlimited| Get-MailboxStatistics | select displayname, lastlogontime | Export-Csv C:\la
    st_logon_time.csv
    + CategoryInfo : ObjectNotFound: (Get-mailbox:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

    Reply
    • Diane Poremsky says

      August 13, 2014 at 12:07 am

      Are you using on premise exchange or office 365?

      Reply
      • Don says

        August 13, 2014 at 2:53 pm

        Exchange 2010 enterprise.

  12. John says

    July 17, 2014 at 11:27 am

    Question regarding LastLogOnTime:

    I am running Exchange 2007 SP1. Is the LastLogOnTime value pulled from AD? Or does Exchange 2007 record this as the last logon to the mailbox?

    The reason I ask is because I have a number of MBs with no LastLogOnTime, but I believe they are active mailboxes (phones, mainly). This would make sense if LastLogOnTime was an AD attribute, since these accounts don't log on to the domain.

    Reply
    • Diane Poremsky says

      July 18, 2014 at 11:44 pm

      Exchange records it. The time is in the AD but it's not an AD logon, it's an exchange logon. (I don't log into a network, only into exchange and the last connection time is listed.)

      Reply
  13. Lorena says

    May 7, 2014 at 1:18 pm

    I agree...the most clear information online!! Thank you so much!!!

    Reply
  14. Harvey Lyau says

    May 2, 2014 at 5:51 pm

    Thank you. You are the most clear, concise and correct information that I have found. I searched among dozens of leads from Google, Bing, TechNet and branching into links long lost. You are a breath of fresh air! Be well and prosper...

    Reply
    • rajanish says

      December 10, 2015 at 4:03 am

      Dear all can you share command
      i want generate report which users not use mails 60 days in exchange 2010
      any gud command

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 31 Issue 7

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Use Classic Outlook, not New Outlook
  • How to Remove the Primary Account from Outlook
  • Reset the New Outlook Profile
  • Disable "Always ask before opening" Dialog
  • How to Hide or Delete Outlook's Default Folders
  • This operation has been cancelled due to restrictions
  • Change Outlook's Programmatic Access Options
  • Adjusting Outlook's Zoom Setting in Email
  • Removing Suggested Accounts in New Outlook
  • Outlook Windows won't open or resize
  • Sync Issues and Errors with Gmail and Yahoo accounts
  • Error Opening iCloud Appointments in Classic Outlook
  • Opt out of Microsoft 365 Companion Apps
  • Mail Templates in Outlook for Windows (and Web)
  • Urban legend: Microsoft Deletes Old Outlook.com Messages
  • Buttons in the New Message Notifications
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Sync Issues and Errors with Gmail and Yahoo accounts

Error Opening iCloud Appointments in Classic Outlook

Opt out of Microsoft 365 Companion Apps

Mail Templates in Outlook for Windows (and Web)

Urban legend: Microsoft Deletes Old Outlook.com Messages

Buttons in the New Message Notifications

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2026 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.