0
 Write-Host "msgId=$msgId"

I'm trying to get a list of only unread emails. I'm able to get the list of emails, but I'm unclear how to add the -Filter parameter.

I've tried each of the following:

$result = Get-MgUserMessage -UserId $email -Filter "IsRead=False"
$result = Get-MgUserMessage -UserId $email -Filter "IsRead=false"
$result = Get-MgUserMessage -UserId $email -Filter "IsRead='false'"
$result = Get-MgUserMessage -UserId $email -Filter "IsRead=$false"
$result = Get-MgUserMessage -UserId $email -Filter "IsRead -eq $false"

I have also tried "isRead" instead of "IsRead" in each of the above. There are some many permutations of how they might have done it, but no examples here: https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.mail/get-mgusermessage?view=graph-powershell-1.0 It just says to pass a string.

All the above attempts return:

Get-MgUserMessage : Invalid filter clause

I'm able to view the IsRead proprety like this, but I my goal is to only get the emails that are not read.

foreach ($item in $result) 
  {
     $msgId  = $item.id 
     $isRead = $item.IsRead
     Write-Host "msgId=$msgId"
     Write-Host "isRead=$isRead"
  }
NealWalters
  • 17,197
  • 42
  • 141
  • 251

1 Answers1

1

Apparently this works, not sure where it is documented:

$result = Get-MgUserMessage -UserId $email -Filter "IsRead eq false"

Got that idea from here: https://theposhwolf.com/howtos/Get-MgUser-Invalid-Filter-Clause/ He said same filters as Get-Msg (https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.users/get-mguser?view=graph-powershell-1.0 - and this page has a few examples).

I kept digging, here are two pages where it's documented:

  1. https://learn.microsoft.com/en-us/graph/query-parameters
  2. https://learn.microsoft.com/en-us/graph/filter-query-parameter

Samples from that page, many more features documented there: enter image description here

NealWalters
  • 17,197
  • 42
  • 141
  • 251
  • You can do type casting too. `get-azureaduser -filter "createddatetime ge datetime'2023-04-13'"` – js2010 Jun 02 '23 at 16:40