question

tonitodux avatar image
0 Votes"
tonitodux asked KyleXu-MSFT commented

PowerShell Query: Display mailbox which has a non-primary e-mail address?

Hi,

when a colleague leaves the company, we usually attach his e-mail address up to two months to a colleague which worked with him so any e-mail can still be processed and answered.
I would like to create a PS Query which shows me the entered smtp address and then displays to which mailbox is this non-primary e-mail address (alias) assigned.

I had this, but it does not work:

Get-Recipient -ResultSize unlimited | Select Name -expand EmailAddresses | Where {$_.SmtpAddress -match ".FIRSTNAME"} | Format-Table Name, SMTPAddress

I tried entering full e-mail address, first couple of letters and then * but it does not show any results. We have Exchange Online.

Cheers

office-exchange-online-itpro
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AndyDavid avatar image
1 Vote"
AndyDavid answered tonitodux commented

You are trying to find a mailbox based on a specific email Address?

 get-mailbox <email Address>

is all you need. it will find it even if its not primary

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi AndyDavid,

you are correct, this worked. Wonder why I didn't think of at the first place.

Thank you and have a great day!

1 Vote 1 ·
tonitodux avatar image
0 Votes"
tonitodux answered KyleXu-MSFT commented

This also works fine when we don't want/know the whole alias address:

Get-EXOMailbox | Where {$_.EmailAddresses -like "SEARCH_TERM"} | select DisplayName, PrimarySMTPAddress

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You can also add “smtp” to this command to search non-primary address:

 Get-Mailbox | where {$_.EmailAddresses -like "smtp:a.a*"} | select DisplayName, PrimarySMTPAddress
0 Votes 0 ·