title: Powershell Get-ChildItem
body: <p>I have a powershell script I wrote to check the contents of a folder and if there is a file with a LastWriteTime older than 20 minutes to notify me.  The problem I am having is when I get the results it is including all of the files in the email body.  How would I write this to get only the latest filename in the email body?    </p>
  
  <pre class="lang-bsh prettyprint-override"><code>$src = 'c:\test'
  $sendmail = $false
  
  Get-ChildItem -path $src | ForEach-Object { 
  #write-host $_.fullname
  $dtdiff = New-TimeSpan ($_.LastWriteTime) $(Get-Date)
  
  if ($dtdiff.TotalMinutes -gt 20){
  $strbody=$strbody +$_.fullname+ " Last File Modified at "  +$_.LastWriteTime +"`r`n"
  $sendmail=$true
  }       
  }
  
  
  #$strbody
   if($sendmail -eq $true){
  # Email components
  $strFromAddress = "abc@xyz.net"
  $strToAddress = "abc@xyz.net"
  $strMessageSubject = "REPORT"
  $strMessageBody = $strbody
  $strSendingServer = "smtp.com"
  $SMTPPort = "587"
  $emailSmtpUser = "abc@xyz.net"
  $emailSmtpPass = "test123"
  # Email objects
  $objSMTPMessage = New-Object System.Net.Mail.MailMessage              $strFromAddress, $strToAddress, $strMessageSubject, $strMessageBody
  $objSMTPClient = New-Object System.Net.Mail.SMTPClient(     $strSendingServer, $SMTPPort )
  $objSMTPClient.EnableSsl = $true
  $objSMTPClient.Credentials = New-Object System.Net.NetworkCredential( $emailSmtpUser , $emailSmtpPass );
  $objSMTPClient.Send($objSMTPMessage)
  }
  </code></pre>