Yes it is. My apologies, I assumed you would use an example. Here is the ps1:
#::-- Param values passed in from Parent script in strict order --::#
Param(
#::-- Required & cannot be Null --::#
[Parameter(Mandatory=$True)]
[ValidateNotNull()]
[string]$EmailSMTPServer,
[Parameter(Mandatory=$True)]
[ValidateNotNull()]
[string]$EmailFrom,
[Parameter(Mandatory=$True)]
[ValidateNotNull()]
[string]$EmailTo,
#::-- Optional & can be Null --::#
[string]$EmailPassword,
[int]$EmailPort
)
#::-- Ensure email recipient string is in proper format --::#
$EmailDelims = (“)|#|$|!|%|&”)
$EmailTo = $EmailTo.Trim() -replace $EmailDelims,“,”
#::-- Check PowerShell Version --::#
If($PSVersionTable.PSVersion.Major -lt 5) {
Throw “WARNING : Please install PowerShell 5.0 or greater to be compatible with this script”
Echo “WARNING : Please install PowerShell 5.0 or greater to be compatible with this script”>>“$Env:LOGFILEemailerror”
}
#::-- Determine Cloud Environment --::#
If(“$Env:INTRAPATH”) {
If(“$Env:CLOUD_URL” -ilike “test”) {
$EmailEnv = “[TEST]”
} Else {
$EmailEnv = “[PROD]”
}
}
If(“$Env:EMAIL_PSSWD”) {
$EmailSecurePassword = Get-Content $EmailPassword | ConvertTo-SecureString
$EmailSecureCreds = New-Object System.Management.Automation.PSCredential ($EmailFrom, $EmailSecurePassword)
$MailParams = @{
SmtpServer = $EmailSMTPServer
From = $EmailFrom
To = $EmailTo.Split(‘,’)
Subject = $Null
Body = $Null
Port = $EmailPort
Credential = $EmailSecureCreds
UseSsl = $True
Priority = $Null
}
} Else {
$MailParams = @{
SmtpServer = $EmailSMTPServer
From = $EmailFrom
To = $EmailTo.Split(‘,’)
Subject = $Null
Body = $Null
Priority = $Null
}
}
#::-- Extensions to exclude from Email Attachments --::#
$EmailExtArray = “deletefile.log”,“.cmd",".bat”,“.exe", ".ps1”, “*.*emailerror”
#::-- Determine if there are any Attachments --::#
$EmailAttachments = Get-ChildItem “$Env:INTRAPATH” -exclude $EmailExtArray </code> <code>| Where-Object { !( $_ | Select-String "0% loss" -quiet) }
| Where { !$_.PSisContainer } |
Select -ExpandProperty FullName
#::-- Add additional attachments if applicable handled in parent batch --::#
$EmailAttachmentsExtra = @(“$Env:MISMATCH_DMFILE”, “$Env:IMPORTERROR_DMFILE”)
ForEach ($EAE In $EmailAttachmentsExtra) {
If ($EAE) {
If(Test-Path $EAE -PathType Leaf) {
$EmailAttachments += $EAE
}
}
}
#::-- Define Attachment Parameter if applicable --::#
If($EmailAttachments){$MailParams.Attachment = $EmailAttachments}
#::-- Determine Script Success from Parent Script via ERR variable --::#
If(“$Env:ERR”){
$MailParams.Subject = “WARNING : $ParentScript Failed $EmailEnv”
$MailParams.Body = “The $EmailEnv $ParentScript process failed to complete successfully.” + “n" + "
n” + “Please the check log file(s) for additional details.” + “n" + "
n”
$MailParams.Priority = “High”
} Else {
$MailParams.Subject = “ATTENTION : $ParentScript Succeeded $EmailEnv”
If(“$Env:INTRAPATH”) {
$MailParams.Body = “The $EmailEnv $ParentScript process completed successfully.” + “n" + "
n” + “Please the check log file(s) for additional details.” + “n" + "
n”
} Else {
$MailParams.Body = “The $EmailEnv $ParentScript process completed successfully.” + “n" + "
n”
}
$MailParams.Priority = “Normal”
}
#::-- Send Email --::#
#::-- Redirect stderr to err file --::#
Try {
Send-MailMessage @MailParams -ErrorAction Stop
}
Catch {
Echo “Failed to send message because: $($Error[0])”>>“$Env:LOGFILEemailerror”
exit 1
}