I am trying to write a powershell script for Exchange Management Shell, importing a list of contacts from a csv file into a distribution group.
I start out with
Import-csv C:\filename.csv | forEach-Object {New-MailContact .......}
This works well, except that some entries in my csv file have a blank email address, and the create teh new contact craps out because ExternalEmailAddress is blank. So, I tried:
Import-csv C:\filename.csv | ForEach-Object { Where-Object {$_.ExternalEmailAddress -ne "" } | New-MailContact -Name $_.Name -ExternalEmailAddress $_.ExternalEmailAddress....}
But that didn't seem to work - it didn't filter out the entries with blank email addresses.
What am I doing wrong?