title: Powershell script to check folder for files and send email
body: <p>I'm trying to get a script to work but I'm running into some issues.  We have a folder that gets ZIP files sent to it via FTP and a service on the server moves them to another directory for processing.  The issue is sometimes the service will be running but not doing anything so the monitoring doesn't sent a alert.  I am working on a PowerShell script to check the folder for .zip files older than 30 minutes and if found send a email to that team to check out why the files haven't been moved.  Below is what I have written so far, any help would be greatly appreciated.  Thanks.</p>
  
  <pre><code>$Path = "c:\test"
  $SMTPServer = "mail.server.com"
  $From = "Monitor Prod &lt;mon.server.com&gt;"
  $To = "people@server.com"
  $Subject = "Alert: Potential issue with service in PROD"
  
  
  $SMTPMessage = @{
  To = $To
  From = $From
  Subject = "$Subject"
  Smtpserver = $SMTPServer
  }
  
  $File = Get-ChildItem -path $path -Filter ".txt" | Where-Object {$_.LastWriteTime -lt (Get-Date).AddMinutes(-30)}
  If ($File)
  {   $SMTPBody = "Batches older than 30 minutes located in c:\test while service is actively running. Service may require a restart."
  $File | ForEach { $SMTPBody += "$($_.FullName)`n" }
  Send-MailMessage @SMTPMessage -Body $SMTPBody
  } 
  </code></pre>