Solved

Attach multiple files into the same PowerShell Script Email message

Posted on 2014-02-06
2
3,512 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
2 Comments
 
LVL 29

Accepted Solution

by:
becraig earned 500 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)
0
 
LVL 1

Author Closing Comment

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

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager
This video discusses moving either the default database or any database to a new volume.

912 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now