Powershell Send Mail Script
This script is designed to Execute a VBS script and then use Powershell to e-mail the VBS created report. To use this script copy the contents of the script into notepad and save the file as FileName.ps1 Remember that in order to run scripts you may need to change the Powershell Execution Policy.
The following variables will need to be changed:
$From = "The e-mail address you wish the script to send mail as"
$To = "The e-mail address you wish to send the mail to"
$Subject = "The subject line of the e-mail"
$Body = "The text you wish to put in the body of the e-mail message"
$FileAttach = "The location and file name of the file you wish to attach to in the e-mail message"
$SMTPServer = "The name or IP of the e-mail server you which will relay the e-mail"
1. Copy the script:
Copy the script and place the script in whatever directory that you will execute it from.
3. Run the script:
Run the script using cscript to send the email notification.
This script can be copied as is. The top half containing fields such as from, to, subject, body, attachments, and the smtp server will need to be modified before execution.
$Date = get-date $From = "firstname.lastname@example.org" $To = "email@example.com" $Subject = "Weekly Log Report - $Date" $Body = "Please browse the included report for a list of Log files that have reached the set retention period and have been deleted" $FileAttach = "C:\Scripts\LogReport.txt" $SMTPServer = "exchange-server.somedomain.com" $Attachment = new-object Net.Mail.Attachment($FileAttach) $SMTP = new-object Net.Mail.SmtpClient($SMTPServer) $MSG = new-object Net.Mail.MailMessage($From, $To, $Subject, $Body) $MSG.attachments.add($Attachment) $SMTP.send($msg)