Powershell Script and WinSCP
Hi All -
I was wondering if i could get some assistance with a powershell/winscp script I am building. It will run in task scheduler every hour, daily, between a certain time slot. The script works - meaning it connects to the remote site and downloads the file(s). What I need, or would like is to pull the file names that were downloaded from the log file created by winscp, and have the names in the email body. Below is the sample script...any help is appreciated.
Clear-Host
$date = Get-Date -format "yyyy-MM-dd HH"
$BaseDir = "SomePath\"
$FileDir = "SomePath\"
Set-location $BaseDir
# Get File - Time Set in Task Scheduler
.\WinSCP.exe /console username@somewhere.com /script=Script.txt /Log=LogFiles/Log-$Date.log
Sleep 120
# Check if File(s) Exists After Download completes
$File = Get-ChildItem "SomePath\*.txt" | where {$_.LastWriteTime.Date -eq ($Date)}
$Checkfile = test-path $File
Get-Content Log-$Date.log
If ($Checkfile -eq $True)
{
Send-MailMessage -To "someone" -From "someone" -Subject "The File Has Downloaded" -SmtpServer "10.10.10.10"
}
else
{
}
I was wondering if i could get some assistance with a powershell/winscp script I am building. It will run in task scheduler every hour, daily, between a certain time slot. The script works - meaning it connects to the remote site and downloads the file(s). What I need, or would like is to pull the file names that were downloaded from the log file created by winscp, and have the names in the email body. Below is the sample script...any help is appreciated.
Clear-Host
$date = Get-Date -format "yyyy-MM-dd HH"
$BaseDir = "SomePath\"
$FileDir = "SomePath\"
Set-location $BaseDir
# Get File - Time Set in Task Scheduler
.\WinSCP.exe /console username@somewhere.com /script=Script.txt /Log=LogFiles/Log-$Date.log
Sleep 120
# Check if File(s) Exists After Download completes
$File = Get-ChildItem "SomePath\*.txt" | where {$_.LastWriteTime.Date -eq ($Date)}
$Checkfile = test-path $File
Get-Content Log-$Date.log
If ($Checkfile -eq $True)
{
Send-MailMessage -To "someone" -From "someone" -Subject "The File Has Downloaded" -SmtpServer "10.10.10.10"
}
else
{
}