Solved

Attach multiple files into the same PowerShell Script Email message

Posted on 2014-02-06
2
3,691 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error 554 5.4.6 Hop count exceeded - possible mail loop 16 47
Power Shell CSV operation 8 31
Exhange 2010 10 35
Office 365 Script for reporting 4 23
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

770 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