List of active mailboxes (PowerShell)

Thanks to PowerShell, you can easily verify the activity on a shared or a user’s mailbox on Exchange (on-premises and Online).

The cmdlets that come in handy in this situation are:

  • Get-MailboxStatistics, which lets us check the Last logon time on a mailbox,
  • And, of course, Get-Mailbox

List of active mailboxes in Powershell

Let’s start with the most basic activity report – a list of users’ and shared mailboxes sorted starting from the most recent logon time.

Here is the script that will let us generate it:

Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox,SharedMailbox | Get-MailboxStatistics | Sort-Object lastlogontime -Descending | Select-Object DisplayName,LastLogonTime

If you don’t need the whole list, just a certain number of most active mailboxes, use the -First parameter in the Select-Object cmdlet:

Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox,SharedMailbox | Get-MailboxStatistics | Sort-Object lastlogontime -Descending | Select-Object –First <number> -Property DisplayName,LastLogonTime

Keep in mind that the script above won’t let you control the activity time range in your list. No worries – that’s where the next script comes in:

Get-Mailbox -ResultSize Unlimited –RecipientTypeDetails UserMailbox,SharedMailbox | Where {(Get-MailboxStatistics $_.Identity).LastLogonTime -gt (Get-Date).AddDays(-30)} | Sort -Property @{e={( Get-MailboxStatistics $_.Identity).LastLogonTime}} -Descending | Select-Object DisplayName,@{n="LastLogonTime";e={(Get-MailboxStatistics $_.Identity).LastLogonTime}}

The key part is the configuration of the Where filter.

In my example it’s configured to list mailboxes which were active in the last 30 days:

(Get-MailboxStatistics $_.Identity).LastLogonTime -gt (Get-Date).AddDays(-30)

But it can be just as easily set up to check activity by hours, minutes, seconds or years. Learn more about date arithmetic in the Get-Date cmdlet

Tips

All of the above results can be exported to CSV files by piping the cmdlets to Export-Csv.

To list inactive mailboxes, simply leave out the -Descending switch in each script.

Further reading

How to start remote PowerShell session to Exchange or Office 365

Support.Office.com: Activity Reports in the Office 365 admin center

Setting an auto reply for shared mailbox

List of active mailboxes (PowerShell) by

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

*