Boomer67
Boomer67

Reputation: 75

The Outlook Inbox Filter doesn't work....why not?

Instead of showing ReceivedTime only for Inbox items for the last two days, this shows for all Inbox items, why?

$objOutlook = new-object -comobject Outlook.Application
$namespace = $objOutlook.GetNameSpace("MAPI")
$InboxFolder = $namespace.GetDefaultFolder(6)

$DateYest = (Get-Date).AddDays(-2)
$InboxFolder | where-object {$_.ReceivedTime -gt "$DateYest"}
ForEach ($MailItem in $InboxFolder) {
write-host $MailITem.ReceivedTime
}

Upvotes: 0

Views: 110

Answers (1)

Doug Maurer
Doug Maurer

Reputation: 8878

The code you posted doesn't return any inbox items. As written you are filtering your one inbox by it's nonexistent RecievedTime property. My assumption is your example is missing the .Items property. If you add .Items to your filter as it stands it wouldn't be captured to a variable or passed down the pipe so it would output directly to the console. However when written properly the filter works fine.

$objOutlook = new-object -comobject Outlook.Application
$namespace = $objOutlook.GetNameSpace("MAPI")
$InboxFolder = $namespace.GetDefaultFolder(6)

$DateYest = (Get-Date).AddDays(-2)
$filteredItems = $InboxFolder.items | where-object {$_.ReceivedTime -gt $DateYest}
foreach ($MailItem in $filteredItems) {
    write-host $MailITem.ReceivedTime
}

or

$objOutlook = new-object -comobject Outlook.Application
$namespace = $objOutlook.GetNameSpace("MAPI")
$InboxFolder = $namespace.GetDefaultFolder(6)

$DateYest = (Get-Date).AddDays(-2)
$InboxFolder.items |
    Where-Object {$_.ReceivedTime -gt $DateYest} |
        ForEach-Object {
            write-host $_.ReceivedTime
        }

Upvotes: 0

Related Questions