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?
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:
Or just use https://github.com/cunninghamp/Get-MailboxReport.ps1 by Paul Cunningham former owenr of https://practical365.com
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