Select A Random Transport Service

I’ve recently created a simple function to select a random transport service on Exchange 2013. My thoughts are that the cmdlet Send-MailMessage only allows specifying a single server and this has been bothering me for a while now. I have many scripts that provide output via email. So what if that server I’ve specified with Send-MailMessage is not available? The script is dead in the water when it comes to reporting. The ability to select a random transport service is nice if your messaging environment does not provide any other means (load balanced relay for example).

My solution to this problem uses nltest.exe to determine the current active directory site in which the script is running. This is useful in the case where you have multiple sites with Exchange 2013 transport services or you are sending notification messages from a management server.

As you may know, just because you have the transport service installed doesn’t mean it is up and running on your server. The function uses the Test-ServiceHealth to determine if MSExchangeTransport is running. If it is running then add the transport service server to the array. Finally, pipe the list of servers to the Get-Random cmdlet to select a random transport service.

The practical usage would be something like this

Leave a Comment