I'm running the following PowerShell code to retrieve matches in my inbox and wondering why my filter isn't working for instances where there's only a single match. Here's the code to find and filter the matches;
Add-type -assembly "Microsoft.Office.Interop.Outlook" | out-null
$olFolders = "Microsoft.Office.Interop.Outlook.olDefaultFolders" -as [type]
$outlook = new-object -comobject outlook.application
$namespace = $outlook.GetNameSpace("MAPI")
$inbox = $namespace.getDefaultFolder($olFolders::olFolderInBox)
$filter = (%{$inbox.items | Where {$_.SenderName -match ‘JoeUser’ -and
$_.UnRead -eq $true}})
...and when I ask for a count of matches by running $filter.count, I get the correct answer AS LONG AS there is more than one match. So, for scenarios where there is only a single, matching message in my inbox, the $filter.count doesn't return anything and teh subsequent code fails to process on the message- and I know that the match picked up the matching message because I can view it from $filter
Can anyone figure out why this count doesn't work on a single match from $filter?