Working in a multi site Exchange 2007 environment can be cumbersome when trying to view queue information on the Hub servers. I wrote this script to simplify this process.
The script queries the Exchange 2007 organization, finds the servers with the Hub Transport Roles, and grouping them into sites (you will have to define the sites yourself, based on your organizational configuration). You can find the sites for your organization by entering this command:
Get-ExchangeServer | Where { $_.isHubTransportServer -eq $true } | sort name
This will output a table of all the Hub Transport servers and list the Site for each. Take these site names, and change the script with your values. You can also modify the variable names to match each site’s name.
Script:
# Exchange 2007 Powershell Script
# Script to display queue information of Hub Transport Servers
# Dynamicly selects Exchange Hub Transport Servers from Exchange 2007 Organization
# Selects server's location by Site
# Output queue information
# Writen by Dan Burgess
# nerd@EverydayNerd.com
cls
# Set variables
$last = "begin"
$choice = 'start'
# Dynamicly set variables for each site's hub transport servers, and sort by server name
$usa = Get-ExchangeServer | where { $_.isHubTransportServer -eq $true -and $_.Site -like '*USA*' } | sort name
$eur = Get-ExchangeServer | Where { $_.isHubTransportServer -eq $true -and $_.Site -like '*EUR*' } | sort name
$chi = Get-ExchangeServer | Where { $_.isHubTransportServer -eq $true -and $_.Site -like '*CHI*' } | sort name
$aus = Get-ExchangeServer | Where { $_.isHubTransportServer -eq $true -and $_.Site -like '*AUS*' } | sort name
$afr = Get-ExchangeServer | Where { $_.isHubTransportServer -eq $true -and $_.Site -like '*AFR*' } | sort name
$allhub = Get-ExchangeServer | Where { $_.isHubTransportServer -eq $true } | sort name
# Start WHILE loop, that allows the user to repeat or select the choice selection instead of exiting the script after completion
while ($choice -ne 'x')
{
write-host ""
write-host "0 - All Sites" -foregroundcolor Yellow
write-host "1 - America (USA)" -foregroundcolor Yellow
write-host "2 - Europe (EUR)" -foregroundcolor Yellow
write-host "3 - China (CHI)" -foregroundcolor Yellow
write-host "4 - Austrialia (AUS)" -foregroundcolor Yellow
write-host "5 - Africa (AFR)" -foregroundcolor Yellow
write-host "6 - All Queue with messages higher than 10" -foregroundcolor Green
write-host "X - Exit" -foregroundcolor Red
write-host ""
# If statement to see check if first selection, or sequencial
if($last -eq "begin")
{
[console]::ForegroundColor = "Green"
$choice = read-host "Select site to check Hub Queue's"
[console]::ResetColor()
}
else
{
[console]::ForegroundColor = "Green"
$choice = read-host "Select site to check Hub Queue's (Press Enter to repeat your last selection)"
[console]::ResetColor()
}
switch ($choice)
{
0 { $hub = $allhub }
1 { $hub = $usa }
2 { $hub = $eur }
3 { $hub = $chi }
4 { $hub = $aus }
5 { $hub = $afr }
6 { $hub = $allhub }
x { }
default { $choice = $last }
}
# For each server in the site selected, get the queue information, and list as a table
if($choice -eq "6")
{
"Begin Hub List" > HubQueueOutput.txt
"--------------------------------------" >> HubQueueOutput.txt
foreach ( $server in $hub )
{
get-exchangeserver $server -erroraction silentlycontinue | get-queue -erroraction silentlycontinue | where {$_.MessageCount -gt 10 } >> HubQueueOutput.txt
}
"--------------------------------------" >> HubQueueOutput.txt
"End Hub List" >> HubQueueOutput.txt
more HubQueueOutput.txt
}
elseif($choice -ne "x")
{
"Begin Hub List" > HubQueueOutput.txt
"--------------------------------------" >> HubQueueOutput.txt
foreach ( $server in $hub )
{
get-exchangeserver $server -erroraction silentlycontinue | get-queue -erroraction silentlycontinue >> HubQueueOutput.txt
}
"--------------------------------------" >> HubQueueOutput.txt
"End Hub List" >> HubQueueOutput.txt
more HubQueueOutput.txt
}
else
{
write-host ""
write-host "Script exiting" -foregroundcolor DarkCyan
write-host ""
write-host "Have a nice day..."
write-host ""
write-host ""
}
$last = $choice
# Go back to begining of WHILE loop, and do it again!
}
Of course this has to be ran on a machine that hat the Exchange 2007 Powershell installed. Hope this helps, and saves time!
