powershell – Powershell to List Sent Items From Shared Mailbox by User

office365outlookpowershell

Is it possible to return a list of all items a user sent from Outlook on a given day, which includes mails they sent from a Shared Mailbox using 'Send As'? Ideally I'd like to use PowerShell.

Example:

  • User A sends 4 emails from their own User Mailbox
  • User A sends 10 emails from a Shared Mailbox that they have 'Send As'
    permissions on

I'd want to see a list of 14 emails. However, when I run the code below I only see the 4 emails they sent from their own user mailbox.

Get-MessageTrace -SenderAddress "[email protected]" –Start "2022-01-20 00:00:00" –End "2022-01-20 23:59:59"

It's an Exchange Online hosted solution, not On-Prem. Any help appreciated!

Best Answer

Run below command

Get-Mailbox –ResultSize unlimited | Search-Mailbox -SearchQuery {sent:1/19/2022..1/22/2022 AND from:[email protected]}-TargetMailbox '[email protected]' -TargetFolder Inbox -LogOnly -LogLevel Full

This command searches all mailbox for messages that sender is user2 and the sent time form 1/19/2022 to 1/22/2022 ,then logs the result in the SearchAndDeleteLog folder in the administrator's mailbox. Messages aren't copied to the target mailbox.