1

I want to get list of all inactive mailboxes with their primary SMTP address and last logon information.

Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Select DisplayName, LastLoggedOnUserAccount, LastLogonTime

This command returns all inactive mailboxes with their display name but problem is that I want to get this list with PrimarySMTPAddress of mailbox because there is a possibility that multiple accounts can have same display name. Is there a way to get it with PrimarySMTPAddress?

3 Answers3

1

The primary SMTP address for an Exchange mailbox is found in its 'ProxyAddresses' attribute. This is a multi-value attribute, and Exchange denotes the primary by using an all-caps 'SMTP:' prefix for the address. Non-primary SMTP addresses will use a lowercase 'smtp:' prefix.

Here's an example of how to query your primary SMTP address:

Get-ADUser -Identity "Muhammad Arsalan Altaf" -Properties ProxyAddresses | select -ExpandProperty ProxyAddresses | ? {$_ -clike "SMTP:*"}
SamErde
  • 3,324
  • 3
  • 23
  • 42
  • thanks for your answer but I want to get their last logon detail. Get-MailboxStatistics returns logon details with many other details but it gives us display name not primary SMTP address. I'm trying to find such a way that it also returns me primary SMTP address with these statistics by running just one script. – Muhammad Arsalan Altaf Apr 10 '20 at 05:33
1
# actually Exchange management shell 
$results = foreach ($mailboxdata in (Get-Mailbox -ResultSize Unlimited)) {
$stats =  Get-MailboxStatistics -identity $mailbox  ;
$mailboxdata | add-member NoteProperty -name LastLoggedOnUserAccount -value  $stats.LastLoggedOnUserAccount 
$mailboxdata | add-member NoteProperty -name LastLogonTime  -value  $stats.LastLogonTime}
$results 

Or just use https://github.com/cunninghamp/Get-MailboxReport.ps1 by Paul Cunningham former owenr of https://practical365.com

0

What the version of your exchange server? If your exchange server is on premise, I found a similar scripts for your reference.

If your exchange server is online, you could Go to https://protection.office.com and sign in using the credentials for an administrator account in your Office 365 organization, Click Information governance > Retention, On the Retention page, click MoreNavigation Bar ellipses, and then click Inactive mailboxes. For more details: View a list of inactive mailboxes

Joy Zhang
  • 1,002
  • 1
  • 4
  • 5