How to get notification of exchange email queue

844 views Asked by At

i want to get the notification of full details of get-queue when my exchange queue reaches maximum message count , here is what i have now which give you the details but not in correct format.

function check_queue
{
$a = get-queue | measure-object MessageCount -max
$b = Get-Queue | Out-File -filepath C:\getQueue.txt

if ($a.Maximum -gt 1000)
{
send_email $a.Maximum
}
}

function send_email
{param ($queue_size)

$emailFrom = "[email protected]"
$emailTo = "[email protected]"
$subject = "Exchange Max Mail QUEUE"
$body = Get-Queue | Out-String
$smtpServer = "mail.xyz.com"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)

}

check_queue

here is the output which is not clear in the format when i get the notification:-

Identi DeliveryType Status MessageCount Velocity RiskLevel OutboundIPPool NextH
ty                                                                        opDom
                                                                          ain  
------ ------------ ------ ------------ -------- --------- -------------- -----
xy... SmtpDeliv... Ready  0            0        Normal    0              ma...
xy... SmtpDeliv... Ready  0            0        Normal    0              ma...
xy... SmtpDeliv... Ready  0            0        Normal    0              ma...
xy... SmtpDeliv... Ready  0            0        Normal    0              ma...
xy... SmtpRelay... Ready  0            0        Normal    0              ed...
xy... Undefined    Ready  0            0        Normal    0              Su...
xy... ShadowRed... Ready  20           0        Normal    0              gr...
1

There are 1 answers

0
Peter Schneider On

If you want to have all details of the object in your output file, you might use the format cmdlets. e.g. format-custom, format-list $body = get-queue | format-list | out-string