Hi all;
I have the following scheduled script, I need the email to be sent to the intended recipient only if the log file contains data because sometimes the generated log file is empty if there are no Fail events.
Please help. Thanks.
Add-PSSnapIn Microsoft.Exchange.Management.PowerShell.E2010
get-messagetrackinglog -ResultSize Unlimited -sender tcn@domain.com -Start (Get-Date).AddDays(-1) -eventid FAIL | Select-Object sender,timestamp,@{Name="Recipients";Expression={$_.recipents}},@{Name="RecipientStatus";Expression={$_.recipientstatus}},messagesubject | Export-CSV D:\CSV\TcnLogs.csv
Send-MailMessage -From "admin@domain.com" -To "TCNeSystemsImports@domain.com" -SmtpServer "exchange.domain.com" -Body "TCN Logs Automated Email" -Subject "TCN Logs" -Attachments "D:\CSV\TcnLogs.csv"