Some software we are using allows us to call a batch file when a certain event happens. So, Im using this to call a batch file which in turn calls a powershell script to send an notification email... A bit long winded I know. ...
So, an example command the software advises is : Cmd.exe /c “c:\process.bat” %1 (where %1 is an parameter ranging from %1 to %9)
At the moment my batch file is :
Code: Select all
echo %date% %time% Data Upload >> C:\upload_log.txt
@echo off
powershell.exe -ExecutionPolicy Unrestricted -Command ". 'C:\UPLOAD_ALERT.ps1'"
Next is the PowerShell Script :
Code: Select all
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { return $true }
$AWS_ACCESS_KEY = "*********************T32"
$AWS_SECRET_KEY = "***********************************"
$SECURE_KEY = $(ConvertTo-SecureString -AsPlainText -String $AWS_SECRET_KEY -Force)
$EmailFrom = "SFTP@mydomain.co.uk"
$EmailTo = "recipient1@mydomain.co.uk"
$Subject = "Upload completed"
$Body = "Hello - a new file has been uploaded"
$SMTPServer = "email-smtp.eu-west-2.amazonaws.com"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($AWS_ACCESS_KEY, $SECURE_KEY);
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
Can anyone advise on how to accomplish this please?
Thanks so much
Fiorano