title: Combining Email code with if statement
body: <p>I'm new to Powershell and am having trouble joining together two scripts I have.
  What I want to do is check the length of all the csv files within a particular folder and if any of them are 0 Kb, I want to send off an alert email. So far I have a script which sends an email successfully and I have a script which checks the size successfully, but I am having trouble joining the two together.</p>
  
  <p>Ideally it would send the name of the files which are empty in the body of the email.</p>
  
  <p>The code below checks the file size and if it is greater than 1Kb it returns true.</p>
  
  <pre><code>    $file = 'FilePath\File1.csv'
      $Result = if (Test-Path $file) { (Get-Item $file).length -gt 1kb }
  
      if ($Result -eq "True") {"File1.csv Contains Data"} ELSE {"File1.csv is      Empty!"}
  
      $file = 'FilePath\File2.csv'
      $Result = if (Test-Path $file) { (Get-Item $file).length -gt 1kb }
  
      if ($Result -eq "True") {"File2.csv Contains Data"} ELSE {"File2.csv is  Empty!"}
  
      $file = 'FilePath\File3.csv'
      $Result = if (Test-Path $file) { (Get-Item $file).length -gt 1kb }
  
      if ($Result -eq "True") {"File3.csv Contains Data"} ELSE   {"File3.csv is Empty!"}
  
      $file = 'FilePath\File4.csv'
      $Result = if (Test-Path $file) { (Get-Item $file).length -gt 1kb }
  
      if ($Result -eq "True") {"File4.csv Contains Data"} ELSE {"File4.csv is Empty!"}
  
      $file = 'FilePath\FileName5.csv'
      $Result = if (Test-Path $file) { (Get-Item $file).length -gt 1kb }
  
      if ($Result -eq "True") {"File5.csv Contains Data"} ELSE {"File5.csv is Empty!"}
  
      $file = 'FilePath\FileName6.csv'
      $Result = if (Test-Path $file) { (Get-Item $file).length -gt 1kb }
  
      if ($Result -eq "True") {"File6.csv Contains Data"} ELSE {"File6.csv is Empty!"}
  </code></pre>
  
  <p>Below is the email portion</p>
  
  <pre><code>    $subject = "Emailtest"
      $body =  "test"
      $emailTo = "jbloggs@Madeup.com"
      $emailFrom ="JohnSmith@123.com"
      $smtpServer = “mail.madeup.com”
      $smtp = new-object Net.Mail.SmtpClient($smtpServer)
      $credentials=new-object system.net.networkcredential(”username”,”password”)
      $smtp.credentials=$credentials.getcredential($smtpserver,"25","basic")
      $smtp.Send($emailFrom, $emailTo, $subject, $body)
  </code></pre>
  
  <p>Thank you for any help.</p>