Solved

Sending email to Multiple parties

Posted on 2013-05-16
5
339 Views
Last Modified: 2013-05-17
Hi Powershell Experts,

I use the following code without problem

send-MailMessage -SmtpServer $smtp -To "user1@xxx.com.sg", "user2@xxx.com.sg" -From $from -Subject $subject -Body $body -BodyAsHtml

But using variable fails???
$to = "user1@xxx.com.sg", "user2@xxx.com.sg"
send-MailMessage -SmtpServer $smtp -To $to  -From $from -Subject $subject -Body $body -BodyAsHtml

Can help explain where I go wrong?
0
Comment
Question by:NicksonKoh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 39173892
that should work:
$recipients = "user1@xxx.com.sg", "user2@xxx.com.sg" 
send-MailMessage -SmtpServer $smtp -To $recipients -From $from -Subject $subject -Body $body -BodyAsHtml

Open in new window

0
 
LVL 17

Author Comment

by:NicksonKoh
ID: 39173933
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 : user1@xxx.com.sg

user2 does not appear in the To list.
0
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
ID: 39173951
Hi,
can you try this:
$to = @("user1@xxx.com.sg", "user2@xxx.com.sg")
0
 
LVL 17

Author Closing Comment

by:NicksonKoh
ID: 39173974
Thx it worked! Does the @() means parameters?
0
 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 39173977
Nope, it means an array of strings (or objects)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question