How to trace unread emails status in specific time/date range for all users in Exchange On-prem

Damien Koh (International Supplier) 0 Reputation points Microsoft Vendor
2024-01-23T07:59:27.5166667+00:00

Hello Team, I have a case where customer request an assistant to trace all unread emails with specific time range in their organization. Is there any way to perform this activity at one go? Any PowerShell script I can find? Environment is Exchange 2016/2019.

Microsoft Exchange Online
Exchange Server
Exchange Server
A family of Microsoft client/server messaging and collaboration software.
1,337 questions
Exchange Server Development
Exchange Server Development
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Development: The process of researching, productizing, and refining new or existing technologies.
549 questions
Microsoft Exchange
Microsoft Exchange
Microsoft messaging and collaboration software.
566 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,597 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Martin Ilesanmi 5 Reputation points
    2024-05-01T13:06:08.2866667+00:00

    Yes, you can use PowerShell to trace all unread emails within a specific time range in an Exchange 2016/2019 environment. Below is a PowerShell script that accomplishes this task:

    
    # Connect to Exchange Server
    
    $UserCredential = Get-Credential
    
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://<ExchangeServerFQDN>/PowerShell/ -Authentication Kerberos -Credential $UserCredential
    
    Import-PSSession $Session -DisableNameChecking
    
    # Define time range (adjust as needed)
    
    $StartDate = Get-Date "YYYY-MM-DD HH:MM:SS"
    
    $EndDate = Get-Date "YYYY-MM-DD HH:MM:SS"
    
    # Get unread emails within the specified time range
    
    $UnreadEmails = Get-Mailbox -ResultSize Unlimited | Search-Mailbox -SearchQuery "Received>='$StartDate' AND Received<='$EndDate' AND IsRead -eq '$false'" -TargetMailbox "DiscoveryMailbox" -TargetFolder "UnreadEmails" -LogLevel Full
    
    # Display results
    
    $UnreadEmails | Select-Object Sender, Subject, Received
    
    # Disconnect from Exchange Server
    
    Remove-PSSession $Session
    
    

    Replace <ExchangeServerFQDN> with the fully qualified domain name of your Exchange Server.

    Make sure to adjust the $StartDate and $EndDate variables to specify the desired time range. The format for the dates should be "YYYY-MM-DD HH:MM:SS".

    This script will search all mailboxes in the Exchange organization for unread emails within the specified time range and display information about the sender, subject, and received date of each unread email.

    Keep in mind that you need appropriate permissions to run this script, such as being a member of the Discovery Management role group or having the necessary permissions assigned.

    Additionally, always test scripts in a non-production environment before running them in a production environment.

    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.