Get-MgUserMessage - duplicates

Evening!

I need to pull all the emails from several users mailboxes, if the mails match my filter, and then do stuff with it.
But i keep having issues, that i get duplicates of the messageId, and i cant seem to figure out why.

$targetFolderName = "Mail Retention cleanup"
$dateThreshold = Get-Date "07-03-2025"
$time = $dateThreshold.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.000Z")
$folder1 = Get-MgUserMailFolder -UserId $manUser -MailFolderId 'deleteditems'
$folder2 = Get-MgUserMailFolder -UserId $manUser -MailFolderId 'sentitems'
$folder3 = Get-MgUserMailFolder -UserId $manUser -Filter "DisplayName eq '$($targetFolderName)'"
$1mails = Get-MgUserMessage -UserId $manUser `
    -Filter "ReceivedDateTime ge $time and not(ParentFolderId eq '$($folder1.Id)' or ParentFolderId eq '$($folder2.Id)' or ParentFolderId eq '$($folder3.Id)')" `
    -All -PageSize 999 `
    -Property ReceivedDateTime, Subject, ParentFolderId, InternetMessageHeaders 

$example = $1mails | Group-Object Id | Where-Object { $_.Count -gt 1 } | Select-Object -First 1
$dupes = $1mails | Where-Object { $_.Id -eq $example.Name }
    
if ($dupes.Subject | Select-Object -Unique | Measure-Object | Where-Object { $_.Count -gt 1 }) {
    Write-Output "Subjects are different"
    $dupes | ForEach-Object { "$($_.Subject.Substring(0,3)) - $($_.Id)" }
}

I am certain that i am missing something completely obvious here, but i cant seem to figure out why i get the duplicates - can you provide a fix?

Please output the message ID and some additional properties, not just the subject, to confirm that you have actually have messages with duplicate message ids. This should rule out whether you have duplicate message IDs in the mailbox (this appears to be possible if a message is copied, based on quick check I just did) or whether it’s a problem with your grouping/filtering.

It was an issue with case sensitivity.
BAAA= / bAAA=