次の方法で共有


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
   }
  }
}

Comments

  • Anonymous
    January 01, 2003
    Jeff, not everyone's a PS purists. I can also start nagging about the error handling ..

  • Anonymous
    January 01, 2003
    hi jeff thanks for the comments, i will re-work the script and repost taking into account the feedback to show the differences ..

  • Anonymous
    November 09, 2011
    Instead of using Write-Host to display the warnings, you might consider using the Write-Warning cmdlet. I would also encourage you to consider writing an object to the pipeline so that you can do more. Right now, all you can do is read the results on the screen. There is no way to save the results to a file, send as a mail message, export to a CSV or anything. You might create a custom object with the computername, the count of messages in the queue, the current datetime and even your status message.