title: Send mail from result (should be easy)
body: <p>I have built a script to check for local machine certificates from a certain issuer expiring within 400.000 days (to get a hit when testing it) on remote server, but i cant just figure out how to get the result to send the actual email as experimenting with pipes after (and in) the IF statements doesnt seem to work.
  I have been googling quiet alot (ofcourse) but as I'm new to Powershell and some code is difficult at times to interpret.</p>
  
  <p>I am looking for something like; if $OutputFromtheIFStatement | Measure-Object -gt 0 { Send email using $SendReportNow.}</p>
  
  <p>My code:</p>
  
  <pre><code>$Servers = 'testserver1,'testserver2'
  $Threshold = 400000 
  $Deadline = (Get-Date).AddDays($Threshold)
  $MailSMTP = '-SmtpServer smtpserver.domain.com -Port 25'
  $MailTo = "receiversmailaddress@company.com"
  $MailFrom = "sendersmailaddress@company.com"
  $MailSubject = '-Subject Certifikat expiring within 90 days'
  $MailBody = '-Body ?'
  $SendReportNow = 'Send-MailMessage $MailSMTP $MailFrom $MailTo $MailSubject'
  Invoke-Command -ComputerName $Servers { Get-ChildItem Cert:\LocalMachine\My } | ForEach { 
  If ($_.NotAfter -le $Deadline -and $_.Issuer -like '*CertainCompanyName*') { $_ | Select @{Label="Servername";Expression={($_.PSComputerName)}}, Issuer, Subject, @{Label="Expiry Date &amp; Time";Expression={($_.NotAfter)}}, @{Label="Expires In (Days)";Expression={($_.NotAfter - (Get-Date)).Days}}
  }
  }
  </code></pre>