« Use tinyget to determine your external IP address | Geta Bako (Japanese shoe box), Part 1 »

Exchange 2003 monitoring with PowerShell (WMI)

First up, simplify your powershell development by getting the PowerShell WMI Explorer. (Think Scriptomatic for PowerShell). Get it here.

I want to modernize some of my monitoring scripts for Exchange 2003 and use PowerShell (of course). Since Exchange 2007 will be the first version with native PowerShell support, we'll have to do our queries through WMI.

Here's a couple of simple ones....

Note: Change ExchangeServer to the hostname for your environment.


Query Status of all SMTP connectors
Query the status of all SMTP connectors and show the names and Up status (true=up, false=down)

get-wmiobject -class "ExchangeConnectorState" -namespace "root\CIMV2\Applications\Exchange" -computername ExchangeServer | select Name,IsUp | Sort-Object -property Name

Query all SMTP Q's and show those with 10 or more queued messages
Dump a list of all SMTP queues with 10 or more queued messages, sorted by number.

get-wmiobject -class "ExchangeLink" -namespace "root\CIMV2\Applications\Exchange" -computername ExchangeServer | select LinkName,NumberOfMessages | where {$_.NumberOfMessages -gt 10} | sort -property NumberOfMessages -desc

Get Exchange Server status (by Admin Group)
Get a list of all Exchange servers and their status. This query is by Admin Group GUID which will allow you to filter out the home office servers that are always down...

get-wmiobject -class "ExchangeServerState" -namespace "root\CIMV2\Applications\Exchange" -computername ExchangeServer | where {$_.GroupGUID -eq "{insert_your_GUID_here}"} | select name,ServerState,Unreachable

This would query for all Exchange servers, regardless of admin group.

get-wmiobject -class "ExchangeServerState" -namespace "root\CIMV2\Applications\Exchange" -computername ExchangeServer | select name,ServerState,Unreachable

Here let's just get the ones that are unreachable

get-wmiobject -class "ExchangeServerState" -namespace "root\CIMV2\Applications\Exchange" -computername ExchangeServer | where {$_.Unreachable -match "False"} | select Name,Unreachable



Send a SMTP report (Simple)

$smtp = new-object Net.Mail.SmtpClient("localhost")
$smtp.Send("from@yourdomain.com", "recipient@theirdomain.com", "insert subject here", "insert body here")

Send a SMTP report (including a log file)

$filename = "logfile.txt"
$smtpServer = "localhost"

$msg = new-object Net.Mail.MailMessage
$att = new-object Net.Mail.Attachment($filename)
$smtp = new-object Net.Mail.SmtpClient($smtpServer)

$msg.From = from@mydomain.com
$msg.To.Add("too@anotherdomain.com")
$msg.Subject = "Nightly Log File"
$msg.Body = "The nightly log file is attached below"
$msg.Attachments.Add($att)

$smtp.Send($msg)



Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)