Roberto Madro R.
asked on
Email the results of an If-Then scenario
I got this powershell script that consists of a Query Part and an Email Part, independently the two parts work fine, but jointly I'm having problem getting them to work properly, in the Query part, I'm saying that if a network file is generated with today's date, send out an email saying "success", else send out an email saying "failed".
that's the extent of it, please advise.
Thx
that's the extent of it, please advise.
Thx
Provide the code, please. It'll be much easier to point out what's required and where.
ASKER
$dir = "C:\FileLocation\FTPVerifi cation"
$latest = Get-ChildItem -Path $dir | sort LastWriteTime | Select-Object -Last 1
#$latest.name
$File = "C:\FileLocation\FTPVerifi cation\*.c sv"
IF($File.LastWriteTime -eq $currentdate)
{Write-host "$latest This EPL File was generated and FTP'd to Vendor today"}
Else
{"No EPL was generated today, please run the process manually"}
# Configure SMTP server
$smtpServer = "10.x.x.x"
$mailMessage = new-object Net.Mail.MailMessage
$smtpObj = new-object Net.Mail.SmtpClient($smtpS erver)
# Set email parameters
$mailMessage.From = "email@company.org"
$mailMessage.ReplyTo = "email@company.org"
$mailMessage.To.Add("vendo r@vendor.o rg")
$mailMessage.subject = "EPL FTP Status"
$mailMessage.body = "This $latest EPL File was generated and FTP'd to CTS today"
$mailMessage.Attachments.A dd($attach ment)
# Send email
$smtpObj.Send($mailMessage )
$attachment.Dispose()
$latest = Get-ChildItem -Path $dir | sort LastWriteTime | Select-Object -Last 1
#$latest.name
$File = "C:\FileLocation\FTPVerifi
IF($File.LastWriteTime -eq $currentdate)
{Write-host "$latest This EPL File was generated and FTP'd to Vendor today"}
Else
{"No EPL was generated today, please run the process manually"}
# Configure SMTP server
$smtpServer = "10.x.x.x"
$mailMessage = new-object Net.Mail.MailMessage
$smtpObj = new-object Net.Mail.SmtpClient($smtpS
# Set email parameters
$mailMessage.From = "email@company.org"
$mailMessage.ReplyTo = "email@company.org"
$mailMessage.To.Add("vendo
$mailMessage.subject = "EPL FTP Status"
$mailMessage.body = "This $latest EPL File was generated and FTP'd to CTS today"
$mailMessage.Attachments.A
# Send email
$smtpObj.Send($mailMessage
$attachment.Dispose()
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent, it worked great, I appreciate it, keep up the good work.