I have a script that will download all the files with today's date. I need to send out an email notification when this script throws an error. I am new to scripting and cannot get these notifications to work. Please take a look and let me know my error.
# Load WinSCP .NET assembly
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
# Set up session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = "test"
UserName = "test"
Password = "test"
SshHostKeyFingerprint = "ssh-rsa 1024 test"
Timeout = New-TimeSpan -Minutes 10
}
$session = New-Object WinSCP.Session
try
{
# Connect
$session.Open($sessionOptions)
$sessionOptions.AddRawSettings("SendBuf", "0")
$sessionOptions.AddRawSettings("SshSimple", "0")
# Set up transfer options
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.FileMask = "*>=1D"
# Transfer files
$session.GetFiles("test/*.txt", "\\Test Scripting\*", $False, $transferOptions).Check()
}
finally
{
$session.Dispose()
}
if( $Error -eq 0 ){
$FailMailParams = @{
To = ''
From = ''
Port = '25'
SmtpServer = ''
Subject = 'Script Errors Out'
Body = 'There was an error with the script!!'
}
}