...hopefully some useful VMware related stuff

List Emails through your Exchange Server between two dates

15/04/2010 12:00

List Emails through your Exchange Server between two dates

 

I was troubleshooting an Email issue on an Exchange server and had sent emails with the subject 'Test'. I wanted to see all messages that matched this subject line in the last two days but thought it would be useful to script it so I could change the amount of days to check back from but also enter a different subject line to check.

 

The script can be downloaded HERE and is attached below:

 

 # Gets all Emails through Exchange server between two dates
# https://www.a2-alpha.co.uk
# 20100417
# Requires PS Snapin: Microsoft.Exchange.Management.PowerShell.Admin
# Or use the Exchange Management Shell on the Exchange Server

#User Input

$numdays = read-host "Enter number of days to go back and check"
$subject = read-host "Search for a particular subject? Default[*]"
if($subject -eq $null)
{
    $subject = "*"
}
$startdate = (get-date).adddays(-$numdays)
$enddate = get-date

#Display

clear
write-output " "
write-output " "
write-output "Checking for messages between $startdate and $enddate with a subject of $subject"
write-output " "
write-output " "

#Getting all the messages

$messages = get-messagetrackinglog -Start $startdate -End $enddate

#Listing the summary of Messages found

foreach($message in $messages)
{
      if($message.MessageSubject -like "$subject")
      {
            $time = $message.Timestamp
            $sender = $message.Sender
            $Recip1 = $message.Recipients[0]
            $Subj = $message.MessageSubject
            $Event = $message.eventid
            write-output "- - - - - - - - - - - - - - - - - -"
            write-output " "
            write-output "Time `t $time"
            write-output "Sender `t $sender"
            write-output "- - - -"
            write-output "Recip1 `t ($Recip1)"
            write-output "- - - -"
            write-output "Subjec `t $Subj"
            write-output "Event `t $event"
            write-output "- - - - - - - - - - - - - - - - - -"
      }
}

Search site