<

PowerShell function to track messages in Exchange 2007

Published on
10,071 Points
3,971 Views
1 Endorsement
Last Modified:
Approved

Why would I want to create a function for tracking messages?

I am glad you asked. As with most monotonous/routine tasks, human error tends to creep in after doing the same task over and over again. By creating a function, you load the function once and then run it. No more rewriting the code each time you want to do the same task.

As for message tracking, the main reason I prefer to use a function is the fact that there are so many different possible arguments you can track against: Sender Name, Recipient name, Start Date, End Date, message ID, internal message ID. That's 8 different arguments making for 256  (2 to the 8th power) different combinations. There will be times where you just want to see all messages sent for a specific time frame to a specific recipient. Or perhaps you just want to see the message traffic from a specific sender, but only the ones that were successfully delivered. There are literally hundreds of possible combinations to search against. But who among us is not ADHD these days and can actually remember all of the combinations all of the time? Well, there are a few, but still, by creating the function, and using it, you simply won't have to.

So, how do I do it?


Another excellent question. You are on a roll. In my script, there are basically two parts.

1. Part 1



In the first part, the function gathers a list of all HUB servers, clears the counter variables and then asks you 8 very pointed questions to determine what your exact search terms are. The answers to these questions are collected and for each one you chose to make part of your search, a binary number is assigned to it using the counter variables (1, 10, 100, 1000, 10000, 100000, 1000000, or 10000000). After all of your answers are gathered, the binary numbers are added up and passed to part two of the function.
Function Track-Message
{
#clear your counter variables
$u = 0
$v = 0
$w = 0
$x = 0
$y = 0
$z = 0
$t = 0
$s = 0
$r = 0
#get a list of all Hubs into an array
$HUB = @(Get-TransportServer)
#ask the questions to track against
$Result1 = read-host "Do you want to search for a certain sender? (Y/N)"
Write-Host
While ($Result1 -eq "Y")
{
	$Sender = read-host "Please specify the sender's SMTP address. (I.E. user@domain.com)"
	Write-Host
	$v = 10000
	$Result1 = "N"
}

$Result2 = read-host "Do you want to search for a certain Recipient? (Y/N)"
Write-Host
While ($Result2 -eq "Y")
{
	$Recipient = read-host "Please specify the recipient's SMTP address. (I.E. user@domain.com)"
	Write-Host
	$w = 1000
	$Result2 = "N"
}

$Result3 = read-host "Do you wish to specify a start date? (Y/N)"
Write-Host
While ($Result3 -eq "Y")
{
	$StartDate = read-host "Please specify the search start date. (I.E. 03/06/2009 12:00:01 PM)"
	Write-Host
	$x = 100
	$Result3 = "N"
}

$Result4 = read-host "Do you wish to specify an end date? (Y/N)"
Write-Host
While ($Result4 -eq "Y")
{
	$EndDate = read-host "Please specify the search end date. (I.E. 03/06/2009 5:00:00 PM)"
	Write-Host
	$y = 10
	$Result4 = "N"
}

$Result5 = read-Host "Do you wish to specify an EventID to search against? (Y/N)"
Write-Host
While ($Result5 -eq "Y")
{
	$EventID = read-host "Please specify which EventID you wish to search against. (BadMail/Defer Delivery/DNS/Expand/Fail/Receive/Redirect/Resolve/Send/Submit/Transfer)"
	Write-Host
	$z = 1
	$Result5 = "N"
}

$Result6 = read-host "Do you wish to specify a message subject to search against? (Y/N)"
Write-Host
While ($Result6 -eq "Y")
{
	$MessageSubj = read-host "Please specify the message subject to search against."
	Write-Host
	$t = 100000
	$Result6 = "N"
}

$Result7 = read-host "Do you wish to specify a message ID to search against? (Y/N)"
Write-Host
While ($Result7 -eq "Y")
{
	$MessageID = read-host "Please specify the message id to search against."
	Write-Host
	$s = 1000000
	$Result7 = "N"
}

$Result8 = read-host "Do you wish to specify an internal message ID to search against? (Y/N)"
Write-Host
While ($Result8 -eq "Y")
{
	$IntMessageID = read-host "Please specify the internal message id to search against."
	Write-Host
	$r = 10000000
	$Result8 = "N"
}

$u = $v + $w + $x + $y + $z + $t + $s + $r

Open in new window


2. Part 2


This is where the cmdlet for get-messagetrackinglog is put together. If you chose to use every option, the binary code would be 11111111, and it would assemble the cmdlet with all options passing your answers in for each argument. Incidentally, the cmdlet would look like this:
get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl

If you only wanted to see the messages with an eventID of Receive (1) to a specific recipient (1000) with a specific subject (100000) regardless of date or any other argument, it would add those up to 101001, pass that into part two of the function and it would return the run the following cmdlet:
get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -MessageSubject $MessageSubj | fl

Now, all of the arguments are passed to the cmdlet from your answers to the questions except the HUB server name. In almost every scenario, it is best to look on all HUB servers in case the message has been bouncing around out there. To make this easy, we simply use the list of all Hub servers that we created in part 1, then do a foreach loop to check each one against the answers you provided.
#pass the arguments to the cmdlet and run it.
Switch ($u)
	{
		11111111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }

		11111110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -Start $StartDate -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11111101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11111011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11111010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -Start $StartDate -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID  | fl
			}
		       }
		11111001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11111000 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11110111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -Start $StartDate -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11110110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -Start $StartDate -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11110101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -Start $StartDate -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11110100 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -Start $StartDate -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11110011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11110010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11110001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11110000 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11101111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11101110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -Start $StartDate -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11101101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11101100 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -Start $StartDate -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11101011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11101010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11101001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11101000 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11100111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -Start $StartDate -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11100110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -Start $StartDate -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11100101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -Start $StartDate -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11100100 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -Start $StartDate -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11100011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11100010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11100001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -MessageSubject $MessageSubj -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11011111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -End $EndDate -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }

		11011110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -Start $StartDate -End $EndDate -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11011101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11011011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -End $EndDate -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11011010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -Start $StartDate -MessageID $MessageID -InternalMessageID $IntMessageID  | fl
			}
		       }
		11011001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11011000 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11010111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -Start $StartDate -End $EndDate -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11010110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -Start $StartDate -End $EndDate -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11010101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -Start $StartDate -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11010100 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -Start $StartDate -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11010011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -End $EndDate -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11010010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -End $EndDate -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11010001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11010000 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11001111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -End $EndDate -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11001110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -Start $StartDate -End $EndDate -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11001101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11001100 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -Start $StartDate -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11001011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -End $EndDate -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11001010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -End $EndDate -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11001001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11000000 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11000111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -Start $StartDate -End $EndDate -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11000110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -Start $StartDate -End $EndDate -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11000101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -Start $StartDate -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11000100 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -Start $StartDate -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11000011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -End $EndDate -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11000010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -End $EndDate -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		11000001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -MessageID $MessageID -InternalMessageID $IntMessageID | fl
			}
		       }
		10111111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -End $EndDate -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }

		10111110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -Start $StartDate -End $EndDate -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }
		10111101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }
		10111011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -End $EndDate -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }
		10111010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -Start $StartDate -MessageSubject $MessageSubj -InternalMessageID $IntMessageID  | fl
			}
		       }
		10111001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }
		10111000 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }
		10110111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -Start $StartDate -End $EndDate -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }
		10110110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -Start $StartDate -End $EndDate -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }
		10110101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -Start $StartDate -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }
		10110100 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -Start $StartDate -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }
		10110011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -End $EndDate -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }
		10110010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -End $EndDate -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }
		10110001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }
		10110000 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }
		10101111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -End $EndDate -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }
		10101110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -Start $StartDate -End $EndDate -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }
		10101101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }
		10101100 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -Start $StartDate -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }
		10101011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -End $EndDate -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }
		10101010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -End $EndDate -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }
		10101001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }
		10101000 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }
		10100111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -Start $StartDate -End $EndDate -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }
		10100110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -Start $StartDate -End $EndDate -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }
		10100101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -Start $StartDate -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }
		10100100 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -Start $StartDate -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }
		10100011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -End $EndDate -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }
		10100010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -End $EndDate -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }
		10100001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -MessageSubject $MessageSubj -InternalMessageID $IntMessageID | fl
			}
		       }
		10011111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -End $EndDate -InternalMessageID $IntMessageID | fl
			}
		       }

		10011110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -Start $StartDate -End $EndDate -InternalMessageID $IntMessageID | fl
			}
		       }
		10011101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -InternalMessageID $IntMessageID | fl
			}
		       }
		10011011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -End $EndDate -InternalMessageID $IntMessageID | fl
			}
		       }
		10011010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -Start $StartDate -InternalMessageID $IntMessageID  | fl
			}
		       }
		10011001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -InternalMessageID $IntMessageID | fl
			}
		       }
		10011000 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -InternalMessageID $IntMessageID | fl
			}
		       }
		10010111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -Start $StartDate -End $EndDate -InternalMessageID $IntMessageID | fl
			}
		       }
		10010110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -Start $StartDate -End $EndDate -InternalMessageID $IntMessageID | fl
			}
		       }
		10010101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -Start $StartDate -InternalMessageID $IntMessageID | fl
			}
		       }
		10010100 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -Start $StartDate -InternalMessageID $IntMessageID | fl
			}
		       }
		10010011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -End $EndDate -InternalMessageID $IntMessageID | fl
			}
		       }
		10010010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -End $EndDate -InternalMessageID $IntMessageID | fl
			}
		       }
		10010001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -InternalMessageID $IntMessageID | fl
			}
		       }
		10010000 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -InternalMessageID $IntMessageID | fl
			}
		       }
		10001111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -End $EndDate -InternalMessageID $IntMessageID | fl
			}
		       }
		10001110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -Start $StartDate -End $EndDate -InternalMessageID $IntMessageID | fl
			}
		       }
		10001101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -InternalMessageID $IntMessageID | fl
			}
		       }
		10001100 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -Start $StartDate -InternalMessageID $IntMessageID | fl
			}
		       }
		10001011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -End $EndDate -InternalMessageID $IntMessageID | fl
			}
		       }
		10001010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -End $EndDate -InternalMessageID $IntMessageID | fl
			}
		       }
		10001001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -InternalMessageID $IntMessageID | fl
			}
		       }
		10001000 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -InternalMessageID $IntMessageID | fl
			}
		       }
		10000111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -Start $StartDate -End $EndDate -InternalMessageID $IntMessageID | fl
			}
		       }
		10000110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -Start $StartDate -End $EndDate -InternalMessageID $IntMessageID | fl
			}
		       }
		10000101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -Start $StartDate -InternalMessageID $IntMessageID | fl
			}
		       }
		10000100 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -Start $StartDate -InternalMessageID $IntMessageID | fl
			}
		       }
		10000011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -End $EndDate -InternalMessageID $IntMessageID | fl
			}
		       }
		10000010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -End $EndDate -InternalMessageID $IntMessageID | fl
			}
		       }
		10000001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -InternalMessageID $IntMessageID | fl
			}
		       }
		10000000 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -InternalMessageID $IntMessageID | fl
			}
		       }
		1111111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }

		1111110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -Start $StartDate -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }
		1111101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }
		1111011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }
		1111010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -Start $StartDate -MessageSubject $MessageSubj -MessageID $MessageID  | fl
			}
		       }
		1111001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }
		1111000 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }
		1110111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -Start $StartDate -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }
		1110110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -Start $StartDate -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }
		1110101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -Start $StartDate -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }
		1110100 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -Start $StartDate -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }
		1110011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }
		1110010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }
		1110001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }
		1110000 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }
		1101111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }
		1101110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -Start $StartDate -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }
		1101101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }
		1101100 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -Start $StartDate -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }
		1101011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }
		1101010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }
		1101001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }
		1101000 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }
		1100111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -Start $StartDate -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }
		1100110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -Start $StartDate -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }
		1100101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -Start $StartDate -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }
		1100100 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -Start $StartDate -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }
		1100011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }
		1100010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -End $EndDate -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }
		1100001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -MessageSubject $MessageSubj -MessageID $MessageID | fl
			}
		       }
		1011111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -End $EndDate -MessageID $MessageID | fl
			}
		       }

		1011110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -Start $StartDate -End $EndDate -MessageID $MessageID | fl
			}
		       }
		1011101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -MessageID $MessageID | fl
			}
		       }
		1011011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -End $EndDate -MessageID $MessageID | fl
			}
		       }
		1011010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -Start $StartDate -MessageID $MessageID  | fl
			}
		       }
		1011001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -MessageID $MessageID | fl
			}
		       }
		1011000 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -MessageID $MessageID | fl
			}
		       }
		1010111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -Start $StartDate -End $EndDate -MessageID $MessageID | fl
			}
		       }
		1010110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -Start $StartDate -End $EndDate -MessageID $MessageID | fl
			}
		       }
		1010101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -Start $StartDate -MessageID $MessageID | fl
			}
		       }
		1010100 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -Start $StartDate -MessageID $MessageID | fl
			}
		       }
		1010011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -End $EndDate -MessageID $MessageID | fl
			}
		       }
		1010010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -End $EndDate -MessageID $MessageID | fl
			}
		       }
		1010001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -MessageID $MessageID | fl
			}
		       }
		1010000 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -MessageID $MessageID | fl
			}
		       }
		1001111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -End $EndDate -MessageID $MessageID | fl
			}
		       }
		1001110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -Start $StartDate -End $EndDate -MessageID $MessageID | fl
			}
		       }
		1001101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -MessageID $MessageID | fl
			}
		       }
		1001100 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -Start $StartDate -MessageID $MessageID | fl
			}
		       }
		1001011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -End $EndDate -MessageID $MessageID | fl
			}
		       }
		1001010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -End $EndDate -MessageID $MessageID | fl
			}
		       }
		1001001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -MessageID $MessageID | fl
			}
		       }
		1000000 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -MessageID $MessageID| fl
			}
		       }
		1000111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -Start $StartDate -End $EndDate -MessageID $MessageID | fl
			}
		       }
		1000110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -Start $StartDate -End $EndDate -MessageID $MessageID | fl
			}
		       }
		1000101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -Start $StartDate -MessageID $MessageID | fl
			}
		       }
		1000100 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -Start $StartDate -MessageID $MessageID | fl
			}
		       }
		1000011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -End $EndDate -MessageID $MessageID | fl
			}
		       }
		1000010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -End $EndDate -MessageID $MessageID | fl
			}
		       }
		1000001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -MessageID $MessageID | fl
			}
		       }
		1000000 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -MessageID $MessageID | fl
			}
		       }
		111111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -End $EndDate -MessageSubject $MessageSubj | fl
			}
		       }

		111110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -Start $StartDate -End $EndDate -MessageSubject $MessageSubj | fl
			}
		       }
		111101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -MessageSubject $MessageSubj | fl
			}
		       }
		111011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -End $EndDate -MessageSubject $MessageSubj | fl
			}
		       }
		111010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -Start $StartDate -MessageSubject $MessageSubj  | fl
			}
		       }
		111001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -MessageSubject $MessageSubj | fl
			}
		       }
		111000 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -MessageSubject $MessageSubj | fl
			}
		       }
		110111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -Start $StartDate -End $EndDate -MessageSubject $MessageSubj | fl
			}
		       }
		110110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -Start $StartDate -End $EndDate -MessageSubject $MessageSubj | fl
			}
		       }
		110101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -Start $StartDate -MessageSubject $MessageSubj | fl
			}
		       }
		110100 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -Start $StartDate -MessageSubject $MessageSubj | fl
			}
		       }
		110011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -End $EndDate -MessageSubject $MessageSubj | fl
			}
		       }
		110010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -End $EndDate -MessageSubject $MessageSubj | fl
			}
		       }
		110001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -MessageSubject $MessageSubj | fl
			}
		       }
		110000 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -MessageSubject $MessageSubj | fl
			}
		       }
		101111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -End $EndDate -MessageSubject $MessageSubj | fl
			}
		       }
		101110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -Start $StartDate -End $EndDate -MessageSubject $MessageSubj | fl
			}
		       }
		101101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -MessageSubject $MessageSubj | fl
			}
		       }
		101100 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -Start $StartDate -MessageSubject $MessageSubj | fl
			}
		       }
		101011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -End $EndDate -MessageSubject $MessageSubj | fl
			}
		       }
		101010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -End $EndDate -MessageSubject $MessageSubj | fl
			}
		       }
		101001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -MessageSubject $MessageSubj | fl
			}
		       }
		101000 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -MessageSubject $MessageSubj | fl
			}
		       }
		100111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -Start $StartDate -End $EndDate -MessageSubject $MessageSubj | fl
			}
		       }
		100110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -Start $StartDate -End $EndDate -MessageSubject $MessageSubj | fl
			}
		       }
		100101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -Start $StartDate -MessageSubject $MessageSubj | fl
			}
		       }
		100100 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -Start $StartDate -MessageSubject $MessageSubj | fl
			}
		       }
		100011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -End $EndDate -MessageSubject $MessageSubj | fl
			}
		       }
		100010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -End $EndDate -MessageSubject $MessageSubj | fl
			}
		       }
		100001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -MessageSubject $MessageSubj | fl
			}
		       }
		100000 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -MessageSubject $MessageSubj | fl
			}
		       }
		11111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -End $EndDate | fl
			}
		       }

		11110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -Start $StartDate -End $EndDate | fl
			}
		       }
		11101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate | fl
			}
		       }
		11011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID -End $EndDate | fl
			}
		       }
		11010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -Start $StartDate  | fl
			}
		       }
		11001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i -EventID $EventID | fl
			}
		       }
		11000 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Recipient $Recipient -Server $i | fl
			}
		       }
		10111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -Start $StartDate -End $EndDate | fl
			}
		       }
		10110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -Start $StartDate -End $EndDate | fl
			}
		       }
		10101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -Start $StartDate | fl
			}
		       }
		10100 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -Start $StartDate | fl
			}
		       }
		10011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID -End $EndDate | fl
			}
		       }
		10010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -End $EndDate | fl
			}
		       }
		10001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i -EventID $EventID | fl
			}
		       }
		10000 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Sender $Sender -Server $i | fl
			}
		       }
		1111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate -End $EndDate | fl
			}
		       }
		1110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -Start $StartDate -End $EndDate | fl
			}
		       }
		1101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -Start $StartDate | fl
			}
		       }
		1100 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -Start $StartDate | fl
			}
		       }
		1011 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID -End $EndDate | fl
			}
		       }
		1010 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -End $EndDate | fl
			}
		       }
		1001 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i -EventID $EventID | fl
			}
		       }
		1000 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Recipient $Recipient -Server $i | fl
			}
		       }
		111 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -Start $StartDate -End $EndDate | fl
			}
		       }
		110 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -Start $StartDate -End $EndDate | fl
			}
		       }
		101 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -Start $StartDate | fl
			}
		       }
		100 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -Start $StartDate | fl
			}
		       }
		11 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID -End $EndDate | fl
			}
		       }
		10 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -End $EndDate | fl
			}
		       }
		1 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i -EventID $EventID | fl
			}
		       }
		0 {foreach ($i in $HUB) 
			{
				get-messagetrackinglog -Server $i | fl
			}
		       }
	}
}

Open in new window


How do you actually run the function?


Well, this is the easy part. Just copy and paste both parts into the Exchange Management Shell, give it a minute to load all lines, and then your function is ready to use. Hit enter a few times to make sure it returns your shell prompt and then type Track-Message and hit enter. It will immediately start asking you the questions and then run the track for you.

Screenshot of Track-Message Function in use.

That's It?

There is one more piece of advice I could offer.If you close the exchange management shell, you will have to copy the function again the next time you open it to track a message. The way around this is to add it to your Microsoft.PowerShell_profile.ps1 file. Where is that? The easiest way to find it is to open exchange management shell and then type $profile. This will return the path to the profile script that runs everything you open Exchange Management Shell under the same user account. The profile is usually stored in a user profile area under documents and settings. So, if I was logged in as GusGallows, mine would be in the following folder:

C:\Documents and Settings\GusGallows\My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

Simply edit that file and copy the whole function (both parts) to the bottom of the file. The next time, and every time after, you open Exchange Management Shell, the function will be preloaded so all you have to do is type Track-Message to run it.

That's it in a nutshell. I hope you found this article useful.
1
Author:GusGallows
Ask questions about what you read
If you have a question about something within an article, you can receive help directly from the article author. Experts Exchange article authors are available to answer questions and further the discussion.
Get 7 days free