We will see here how to search or trace Microsoft 365 emails with PowerShell.
First thing to do is to install the Microsoft Exchange Online PowerShell Console which will allow us to connect to Microsoft 365 account via PowerShell. To do so you can use this beautiful article.
PS C:\> Connect-EXOPSSession -UserPrincipalName admin@std.rocks
⚠️ It is not possible to search back more than 10 days.⚠️
Now everything is set and that we are connected to our Microsoft 365 account we can do some emails search.
PS C:\> Get-MessageTrace -StartDate $(get-date).AddDays(-10) -EndDate $(get-date) | Where-Object { $_.SenderAddress -match 'std.rocks' }
PS C:\> Get-MessageTrace -StartDate $(get-date).AddDays(-10) -EndDate $(get-date) | Select-Object Received, SenderAddress, RecipientAddress, Subject, Status, ToIP, FromIP, Size, MessageID, MessageTraceID | Where-Object { $_.SenderAddress -match 'std.rocks' }
PS C:\> Get-MessageTrace -StartDate $(get-date).AddDays(-5) -EndDate $(get-date) | Select-Object * | Where-Object { $_.SenderAddress -match 'std.rocks' -and $_.RecipientAddress -match 'user@shebangthedolphins.net' }
Contact :