First, you're trying too hard. You're looping through your emails twice looking for the exact same email, and that's just redundant. Second, Get-Date <DateTime Object/DateTime String>
is your friend, but you don't even need it. If you really, really, really want to sort the emails and select the date/time of the first one, then filter them for that one date/time I suppose you can, and here's what you'd want:
if ((get-date $_.ReceivedTime) -eq (get-date $date))
I think a better solution would be replacing:
$date = $f.Items| Select-Object -Property ReceivedTime | Sort-Object ReceivedTime -Descending | Select-Object -Index 0
with:
$email = $f.Items| Sort-Object ReceivedTime -Descending | Select-Object -First 1
Then you can do things like:
Write-Output "Last email received at $($email.receivedtime), attached file(s) are: (if any)
$email.attachments|%{Write-Output $_.filename}
and
$email.attachments|%{$_.saveasfile((join-path $folder $_.filename))
Personally I'd add a If($email.attachments.count -gt 0){Do Stuff}else{Write-Output "Latest email at $($email.receivedtime) has no attachments!"}
bit in there.