3

I am trying to get a list of all email addresses that we have registered in our on-prem Exchange but I want to exclude all of the X400 type addresses. I have tried all of the following commands:

Get-Recipient | select name,recipienttype -expand emailaddresses | select name,recipienttype,prefix,addressstring,isprimaryaddress | where -property prefix -eq 'SMTP'
Get-Recipient | select name,recipienttype -expand emailaddresses | select name,recipienttype,prefix,addressstring,isprimaryaddress | where {$_.prefix -eq 'SMTP'}
Get-Recipient | select name,recipienttype -expand emailaddresses | select name,recipienttype,prefix,addressstring,isprimaryaddress | where-object {$_.prefix -eq 'SMTP'}
Get-Recipient | select name,recipienttype -expand emailaddresses | where-object {$_.prefix -eq 'SMTP'} | select name,recipienttype,prefix,addressstring,isprimaryaddress
Get-Recipient | select name,recipienttype -expand emailaddresses | where-object -property Prefix -eq 'SMTP' | select name,recipienttype,prefix,addressstring,isprimaryaddress

If I exclude the where-object, it returns everything fine. What am I missing? I am using the Exchange Management Shell running Powershell 5.1.

Caynadian
  • 432
  • 2
  • 9
  • 24

2 Answers2

2

You're missing that the Prefix property is not a string. You could call the ToString method but as there is PrefixString available it would be simpler to use that.

Get-Recipient | select name,recipienttype -expand emailaddresses | select name,recipienttype,prefixstring,addressstring,isprimaryaddress | ? { $_.PrefixString -eq "smtp" }
jfrmilner
  • 406
  • 2
  • 6
-1

You can try the following command to list all SMTP email addresses.

Get-Recipient | Select Name -ExpandProperty EmailAddresses | Select Name,  SmtpAddress

If you want to export the output with a csv file.

Get-Recipient | Select Name -ExpandProperty EmailAddresses | Select Name, SmtpAddress | Export-csv c:\mailAddress.csv
Aaron
  • 359
  • 4
  • Thanks but this doesn't really address my question which is how to properly filter out the X400 addresses from the results. – Caynadian Sep 05 '22 at 12:41