Sending email to Multiple parties

Hi Powershell Experts,

I use the following code without problem

send-MailMessage -SmtpServer $smtp -To "", "" -From $from -Subject $subject -Body $body -BodyAsHtml

But using variable fails???
$to = "", ""
send-MailMessage -SmtpServer $smtp -To $to  -From $from -Subject $subject -Body $body -BodyAsHtml

Can help explain where I go wrong?
LVL 17
Who is Participating?
Rainer JeschorConnect With a Mentor Commented:
can you try this:
$to = @("", "")
Meir RivkinFull stack Software EngineerCommented:
that should work:
$recipients = "", "" 
send-MailMessage -SmtpServer $smtp -To $recipients -From $from -Subject $subject -Body $body -BodyAsHtml

Open in new window

NicksonKohAuthor Commented:
Hi sedgwick,

I just tested again and while there is no error, it is still not working correctly as the email is only sent to the first person in $recipients. So for the above case, I receive an email with just

To :

user2 does not appear in the To list.
NicksonKohAuthor Commented:
Thx it worked! Does the @() means parameters?
Rainer JeschorCommented:
Nope, it means an array of strings (or objects)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.