This might sound like a stupid question, but I would like to know how to import some mail addresses into PowerShell to send one mail to all of them like Send-MailMessage -To $MailTo.
I already managed to remove the text MailTo: in the beginning of the line. The example will make it more clear:
Input file:
# Comment
MailTo: User1@domain.com, User2@domain.com, User3@domain.com
MailTo: User4@domain.com, User5@domain.com, User6@domain.com, User7@domain.com, User8@domain.com
The code:
$File = (Get-Content -Path $ImportFile) -notlike '#*' | Foreach {$_.TrimEnd()} | Where {$_ -ne ""}
$MailTo = $File | where { $_ -like "MailTo:*" } | Foreach {$_ -replace "^MailTo: "}
Solution:
$MailTo = ($File | where { $_ -like "MailTo:*" } | Foreach {$_ -replace "^MailTo: "}) -split ',\s*' | Foreach {$_.Trim()} | Where {$_}
Thanks to Joey below.