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.