Powershell script to send three attachment

twinbaby

Supremacy Member
Joined
Jul 8, 2014
Messages
5,470
Reaction score
1,534
Hi there,

How do I modify the script such that it can take in three parameter to send 3 attachment instead of one attachment?

param( [string]$t = "t", [string]$a = "a")
$t = $t -split ","
$pwd = ConvertTo-SecureString ‘mypassword’ -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential someone@someone.com,$pwd
$param = @{
SmtpServer = 'smtp.someone.com'
Port = 25
UseSsl = $false
Credential = $cred #remove this if SMTP authentication is not required
From = 'someone@someone.com'
To = $t
Subject = 'Scan results from Checkmarx'
Body = "Please find scan results attached."
Attachments = $a
}
Send-MailMessage @param
 

BlackCube

Great Supremacy Member
Joined
Jul 18, 2003
Messages
71,252
Reaction score
861
You can do similar stuff to your $t.

$a = $a -split ","

I think might work.
 

BlackCube

Great Supremacy Member
Joined
Jul 18, 2003
Messages
71,252
Reaction score
861
It is to split string into substring.

I'm not sure how your script work but this should be how it is to add multiple attachment.

Code:
Send-MailMessage -To “Manager 1 <Manager1@xyz.com>" -From “Reports Admin <Reportadmin@xyx.com>" -SMTPServer smtp1.xyz.com -Subject “Daily report” -Body “Attached file has uptime details of all servers” -Attachments “c:\temp\server1-uptime-report.txt”, “c:\temp\server2-uptime-report.txt”

Source
 

twinbaby

Supremacy Member
Joined
Jul 8, 2014
Messages
5,470
Reaction score
1,534
Hi there,

I have managed to done it.
How can I zip up all 3 attachment and send it out instead?
 
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ Forums. Forum members and moderators are responsible for their own posts. Please refer to our Community Guidelines and Standards and Terms and Conditions for more information.
Top