Get email Attachment from today only
<p>I would like to get a .txt file from my outlook email that has the current date.
so far it will grab anything that has a '.txt' atachment.
How would I format it so it gets the email sent from today's date <strong>ONLY</strong>.</p>

<p>I will be receiving <strong>1</strong> daily email in this folder, so I want to grab that daily file's attachment and place it in folder in my directory.
So far I have this:</p>

<pre><code>$i=1

#set outlook to open
$o = New-Object -comobject outlook.application
$n = $o.GetNamespace(“MAPI”)


$f = $n.pickfolder('EDI')


$filepath = “C:\users\cesar.sanchez\desktop\EDI Statement Extract”

$date = get-date (Get-Date).AddDays(-1) -format "MMMM dd"


$f.Items | foreach {
$i=$i+1
    $_.attachments | foreach {
    Write-Host $_.filename
    $a = $_.filename
    If ($a.Contains(“.txt”)) {
    $_.saveasfile((Join-Path $filepath “Nassau EDI ExtractTest _$date.txt”))
      }
  }
}
</code></pre>