I have been looking recently and I have been struggling to find any articles that showed me how to only get an export of external email contacts. All the blogs I’ve seen is just gathering every single contact, here’s what I used!

For easy access here is the code:

Get-MailContact -ResultSize Unlimited | Where-Object {_.externalemailaddress -notlike “*@<yourdomain.com>”} | Select-Object Name,ExternalEmailAddress,*when* | export-csv c:\users\user.name\documents\onpremexternalobjects.csv

That will filter out any users that have an email address containing your domain name.

Hope this helps!

About the author