?
Solved

Attach multiple files into the same PowerShell Script Email message

Posted on 2014-02-06
2
Medium Priority
?
4,356 Views
Last Modified: 2014-02-06
Hi Guys,

I am new with Poweshell Script. Pretty new!  :-)
Please be patient!
I found the following code to email me attachments.
However I need $attachment and $attachment2
Currently I am getting only $attachment

How should I change the script below to attach both attachments?


###########Define Variables########
 
$fromaddress = "donotreply@domain.com"
$toaddress = "administrator@domain.com"
$bccaddress = "administrator@domain.com"
$CCaddress = "administrator@domain.com"
$Subject = "Mailbox Statistics Weekly Export"  
$attachment = "C:\scripts\ExportMailboxStats.csv"
$attachment2 = "C:\scripts\LabUsers.csv"
$smtpserver = "smtp.domain.com"
 
####################################
 
$message = new-object System.Net.Mail.MailMessage
$message.From = $fromaddress
$message.To.Add($toaddress)
$message.CC.Add($CCaddress)
$message.Bcc.Add($bccaddress)
$message.IsBodyHtml = $True
$message.Subject = $Subject
$attach = new-object Net.Mail.Attachment($attachment)
$message.Attachments.Add($attach)
$message.body = $body
$smtp = new-object Net.Mail.SmtpClient($smtpserver)
$smtp.Send($message)
 
######################################
0
Comment
Question by:osagarana
[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 Comments
 
LVL 29

Accepted Solution

by:
becraig earned 2000 total points
ID: 39840845
$message = new-object System.Net.Mail.MailMessage
$message.From = $fromaddress
$message.To.Add($toaddress)
$message.CC.Add($CCaddress)
$message.Bcc.Add($bccaddress)
$message.IsBodyHtml = $True
$message.Subject = $Subject
$message.Attachments.Add($attachment)
$message.Attachments.Add($attachment2)
$message.body = $body
$smtp = new-object Net.Mail.SmtpClient($smtpserver)
$smtp.Send($message)
1
 
LVL 1

Author Closing Comment

by:osagarana
ID: 39840915
thanks mate. It worked.  :-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
how to add IIS SMTP to handle application/Scanner relays into office 365.
Suggested Courses

777 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