Link to home
Start Free TrialLog in
Avatar of Roberto Madro R.
Roberto Madro R.Flag for United States of America

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
Avatar of footech
footech
Flag of United States of America image

Provide the code, please.  It'll be much easier to point out what's required and where.
Avatar of Roberto Madro R.

ASKER

$dir = "C:\FileLocation\FTPVerification"
$latest = Get-ChildItem -Path $dir | sort LastWriteTime | Select-Object -Last 1
#$latest.name
$File = "C:\FileLocation\FTPVerification\*.csv"
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($smtpServer)

# Set email parameters
$mailMessage.From = "email@company.org"
$mailMessage.ReplyTo = "email@company.org"
$mailMessage.To.Add("vendor@vendor.org")
$mailMessage.subject = "EPL FTP Status"
$mailMessage.body = "This   $latest   EPL File was generated and FTP'd to CTS today"
$mailMessage.Attachments.Add($attachment)

# Send email
$smtpObj.Send($mailMessage)
$attachment.Dispose()
ASKER CERTIFIED SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Excellent, it worked great, I appreciate it, keep up the good work.