Export a list of email messages in Quarantine to a csv file.

Jamie Schaub 40 Reputation points
2025-01-16T22:04:47.1033333+00:00

I am looking for a PowerShell script or instructions on how to export all O365 quarantined messages in my tenant over a specific period of time into a CSV file.

Exchange Online
Exchange Online
A Microsoft email and calendaring hosted service.
6,188 questions
Microsoft 365 and Office | Install, redeem, activate | For business | Windows
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2025-01-17T05:38:23.3266667+00:00

    Hello, @Jamie Schaub,

    Welcome to the Microsoft Q&A platform!

    You can use to export all quarantined messages in your Office 365 tenant over a specific period into a CSV file according to my instructions and PowerShell script below.

    1.Use "Get-QuarantineMessage" to list your email messages in Quarantine.

    2.Use the following cmdlet to export all O365 quarantined messages in your tenant over a specific period of time into a CSV file.

    Get-QuarantineMessage  | Select-Object ReceivedTime, Type, SenderAddress, Subject, Expires | Where-Object { $_.ReceivedTime -ge '01/11/2025' -and $_.ReceivedTime -le '01/30/2025' } ` | Export-Csv -Path 'C:\test117\test1.csv' -NoTypeInformation
    

    (Note: The "01/11/2025" and "01/30/2025" is the start date and end date of your emails you want to export. The "C:\test117\test1.csv" is the location you want to export your emails to.)

    3.The test result is shown below.

    User's image

    Should you need more help on this, you can feel free to post back. 


    If the answer is helpful, please click on “Accept answer” as it could help other members of the Microsoft Q&A community who have similar questions and are looking for solutions.

    User's image Thank you for your support and understanding.

    Best Wishes,

    Alex Zhang


2 additional answers

Sort by: Most helpful
  1. Amit Singh 5,306 Reputation points
    2025-01-17T04:55:28.8866667+00:00

    Hi @Jamie Schaub To export all quarantined messages in your Office 365 tenant over a specific period to a CSV file using PowerShell, you can use the Get-QuarantineMessage cmdlet. This cmdlet allows you to pull details about quarantined emails in your tenant.

    The following command lists all quarantined emails for a specific user for a given period of time. 

    Get-QuarantineMessage -StartReceivedDate 01/01/2025 -EndReceivedDate 01/17/2025|Where{$_.RecipientAddress -eq <UserPrincipalName>}| Select ReceivedTime, RecipientAddress,SenderAddress,Subject,MessageID,RecipientCount,QuarantineTypes| Export-Csv -Path "D:\QuarantinedEmailsReceivedBySpecificUser.csv" -NoTypeInformation -Append –Force
    

    Another way, From Quarantine center, you could choose all quarantined emails, then export them in to a ".zip" file.

    Let me know if you want to explore another option.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments

  2. Amit Singh 5,306 Reputation points
    2025-01-17T05:09:16.8166667+00:00

    To export all quarantined messages in your Office 365 tenant over a specific period to a CSV file using PowerShell, you can use the Get-QuarantineMessage cmdlet. This cmdlet allows you to pull details about quarantined emails in your tenant.

    The following command lists all quarantined emails for a specific user for a given period of time.

    Get-QuarantineMessage -StartReceivedDate 01/01/2025 -EndReceivedDate 01/17/2025|Where{$_.RecipientAddress -eq <UserPrincipalName>}| Select ReceivedTime, RecipientAddress,SenderAddress,Subject,MessageID,RecipientCount,QuarantineTypes| Export-Csv -Path "D:\QuarantinedEmailsReceivedBySpecificUser.csv" -NoTypeInformation -Append –Force
    

    Another way, From Quarantine center, you could choose all quarantined emails, then export them in to a ".zip" file.

    Let me know if you want to explore through Quarantine center.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.