Created
April 16, 2014 19:44
-
-
Save iqwirty/10925261 to your computer and use it in GitHub Desktop.
Sends an email from a script with an optional attachment. Includes path of currently running script in body.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function EmailScriptReport | |
{ | |
# Sends an email using the specified to/from, subject, body, and | |
# and SMTP server. Allows an attachment to be included. Also includes | |
# in the body the source path of the running script to improve | |
# traceability. | |
Param ( | |
[string]$To, | |
[string]$From, | |
[string]$Server, | |
[string]$Subject, | |
[string]$Body, | |
[string]$AttachmentFullPath, | |
[string]$EmailSource | |
) | |
$parentInvocation = (Get-Variable MyInvocation -Scope 1).Value | |
$formattedBody = "$Body`r`n`r`nSent by a script at:`r`n$($parentInvocation.ScriptName)" | |
Send-MailMessage -To $To ` | |
-From $From ` | |
-SmtpServer $Server ` | |
-Subject $Subject ` | |
-Body $formattedBody ` | |
-Attachments $AttachmentFullPath | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment