Skip to content
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
35 lines (24 sloc) 1.27 KB
Script provided as is. Use at own risk. No guarantees or warranty provided.
Script designed to display a trace of all emails sent in recent hours to screen
Source -
Prerequisites = 1
1. Ensure connection to Exchange Online has already been completed
More scripts available by joining
## Variables
$systemmessagecolor = "cyan"
$processmessagecolor = "green"
$errormessagecolor = "red"
$warnmessagecolor = "yellow"
$hours = 48 ## Number of prior hours to check
## If you have running scripts that don't have a certificate, run this command once to disable that level of security
## set-executionpolicy -executionpolicy bypass -scope currentuser -force
write-host -foregroundcolor $systemmessagecolor "Script started`n"
$dateEnd = get-date  ## get current time
$dateStart = $dateEnd.AddHours(-$hours) ## get current time less last $hours
$results = Get-MessageTrace -StartDate $dateStart -EndDate $dateEnd | Select-Object Received, SenderAddress, RecipientAddress, Subject, Status, ToIP, FromIP, Size, MessageID, MessageTraceID
$results | out-gridview
write-host -foregroundcolor $systemmessagecolor "Script completed`n"
You can’t perform that action at this time.