• 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

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.

Subscribe
Notify of
28 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

ShandyT
January 15, 2022 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.

Last edited 3 years ago by ShandyT
0
0
Reply
Diane Poremsky
Author
Reply to  ShandyT
January 17, 2022 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

0
0
Reply
Arsal
May 15, 2020 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?

0
0
Reply
Dave
August 15, 2017 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?

0
0
Reply
Diane Poremsky
Author
Reply to  Dave
August 15, 2017 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.

0
0
Reply
Dennis
June 5, 2017 4:16 am

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

After all we are talking PowerShell :)

0
0
Reply
Diane Poremsky
Author
Reply to  Dennis
June 5, 2017 8:09 am

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

1
0
Reply
Johan
January 8, 2017 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.

0
0
Reply
Diane Poremsky
Author
Reply to  Johan
January 9, 2017 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.

0
0
Reply
jesus
May 24, 2016 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

0
0
Reply
Diane Poremsky
Author
Reply to  jesus
May 24, 2016 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.

0
0
Reply
jesus
Reply to  Diane Poremsky
May 24, 2016 3:36 pm

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

0
0
Reply
Diane Poremsky
Author
Reply to  jesus
August 18, 2016 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

0
0
Reply
Ron Walters
April 14, 2016 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 ?

0
0
Reply
Diane Poremsky
Author
Reply to  Ron Walters
April 14, 2016 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.

0
0
Reply
Greg Lamb
July 5, 2015 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??

0
0
Reply
Diane Poremsky
Author
Reply to  Greg Lamb
July 6, 2015 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.

0
0
Reply

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

Latest EMO: Vol. 30 Issue 29

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
  • Jetpack plugin with Stats module needs to be enabled.
  • 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
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
  • New Outlook: Show To, CC, BCC in Replies
  • Insert Word Document into Email using VBA
  • Delete Empty Folders using PowerShell
  • Warn Before Deleting a Contact
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

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

Import EML Files into New Outlook

Opening PST files in New Outlook

New Outlook: Show To, CC, BCC in Replies

Insert Word Document into Email using VBA

Delete Empty Folders using PowerShell

Warn Before Deleting a Contact

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 © 2025 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

:wpds_smile::wpds_grin::wpds_wink::wpds_mrgreen::wpds_neutral::wpds_twisted::wpds_arrow::wpds_shock::wpds_unamused::wpds_cool::wpds_evil::wpds_oops::wpds_razz::wpds_roll::wpds_cry::wpds_eek::wpds_lol::wpds_mad::wpds_sad::wpds_exclamation::wpds_question::wpds_idea::wpds_hmm::wpds_beg::wpds_whew::wpds_chuckle::wpds_silly::wpds_envy::wpds_shutmouth:
wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment