?
Solved

conditional email in powershell script

Posted on 2013-10-30
2
Medium Priority
?
360 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

777 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