Solved

conditional email in powershell script

Posted on 2013-10-30
2
333 Views
Last Modified: 2013-10-30
This script works but errors if the file it is reading is empty.

How can i make the email conditional on the file not being empty.

 $Line = Get-Content E:\MonitorFolder\PingResults.txt
   
  Send-MailMessage -From 'Lost_Network_Connection_16@company.com' -To 'me@company.com' `
  -SmtpServer 'smtp.company.com' `
  -Subject 'Lost Network Connection' `
  -BodyAsHtml `
    -Body  ($Line -join "<br>")
0
Comment
Question by:jimmylew52
2 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 39611844
Try...
 $Line = Get-Content E:\MonitorFolder\PingResults.txt
  
If ($line -ne $null) {
  Send-MailMessage -From 'Lost_Network_Connection_16@company.com' -To 'me@company.com' `
  -SmtpServer 'smtp.company.com' `
  -Subject 'Lost Network Connection' `
  -BodyAsHtml `
    -Body  ($Line -join "<br>") 
}

Open in new window

0
 
LVL 1

Author Comment

by:jimmylew52
ID: 39612116
Works, thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now