powershell - checking exchange 2010 queues using WMI
just in case you are not allowed open remote powershell or something like that, here is a quick way to collect the information via WMI from a remote computer...
# Setting path to servers.txt file for input later on...
$inputfilepath = $env:USERPROFILE + "\Desktop"
$inputfilename = "servers.txt"
$workingfile = $inputfilepath + "\" + $inputfilename
#does the file exist?
$fileexist = test-path $workingfile
if ($? -eq $false)
{
Write-Host "$inputfilename does not exist on $infputfilepath" -ForegroundColor Red -BackgroundColor Black
Write-Host "Please Create the file with one server per line that you want checked" -ForegroundColor Red -BackgroundColor Black
exit 1
}
#read the file into a variable for later processing
$servers = Get-Content $workingfile
$WarningLevel = 10
$CriticalLevel = 20
Foreach ($s in $servers)
{
#this part tests for port 25 open which is a good sign its a hub transport server!
$port = 25
$ErrorActionPreference = “SilentlyContinue”
$socket = new-object Net.Sockets.TcpClient
$socket.Connect($s, $port)
if ($socket.Connected)
{
$connect = $true
$socket.Close()
}
else
{
$connect = $false
}
$socket = $null
if ($connect -eq $true)
{
$MessagesQueued = get-wmiobject -ComputerName $s -query "select MessagesQueuedForDelivery from Win32_PerfFormattedData_MSExchangeTransportQueues_MSExchangeTransportQueues"
$Messages = $MessagesQueued.MessagesQueuedForDelivery
if ($Messages -gt $CriticalLevel )
{
Write-Host "Messages Queues BAD" -ForegroundColor Red -BackgroundColor Black
}
elseif ($Messages -ge $WarningLevel)
{
Write-Host "Messages Queues Need to be monitored" -ForegroundColor Yellow -BackgroundColor Black
}
else
{
Write-Host "Message Queues Appear Healthy" -ForegroundColor Green -BackgroundColor Black
}
}
}