{"id":125,"date":"2018-09-10T09:28:38","date_gmt":"2018-09-10T13:28:38","guid":{"rendered":"http:\/\/www.thelamberts.com\/wiki\/?p=125"},"modified":"2018-09-10T09:29:25","modified_gmt":"2018-09-10T13:29:25","slug":"check-exchange-queue-send-an-email-if-queue-over-a-specified-limit","status":"publish","type":"post","link":"http:\/\/www.thelamberts.com\/wiki\/2018\/09\/10\/check-exchange-queue-send-an-email-if-queue-over-a-specified-limit\/","title":{"rendered":"Check Exchange queue, send an email if queue over a specified limit."},"content":{"rendered":"<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\nfunction check_queue\r\n {\r\n $QueueCount = get-transportserver | get-queue | measure-object MessageCount -max\r\n\r\n# Set the limit here \r\nif ($QueueCount.Maximum -gt 20)\r\n {\r\n send_email $QueueCount.Maximum\r\n exit\r\n }\r\n\r\n# How often to check\r\n start-sleep -s 300\r\n check_queue\r\n }\r\n \r\nfunction send_email\r\n {param ($queue_size)\r\n \r\n$emailFrom = &quot;from@who.com&quot;\r\n $emailTo = &quot;to@who.com&quot;\r\n $subject = &quot;Exchange queue at $queue_size&quot;\r\n $body = &quot;Mail queues are high, last seen at $queue_size&quot;\r\n $smtpServer = &quot;smtp.mydomain.net&quot;\r\n $smtp = new-object Net.Mail.SmtpClient($smtpServer)\r\n $smtp.Send($emailFrom, $emailTo, $subject, $body)\r\n \r\n}\r\n \r\ncheck_queue\r\n<\/pre>\r\n\r\nUse the start-job command.\r\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\nstart-job .\/CheckQueue.ps1<\/pre>","protected":false},"excerpt":{"rendered":"function check_queue { $QueueCount = get-transportserver | get-queue | measure-object MessageCount -max # Set the limit here if ($QueueCount.Maximum -gt 20) { send_email $QueueCount.Maximum exit } # How often to check start-sleep -s 300 check_queue } function send_email {param ($queue_size) $emailFrom = &quot;from@who.com&quot; $emailTo = &quot;to@who.com&quot; $subject = &quot;Exchange queue at $queue_size&quot; $body = &quot;Mail [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,3],"tags":[],"class_list":["post-125","post","type-post","status-publish","format-standard","hentry","category-exchange","category-powershell"],"_links":{"self":[{"href":"http:\/\/www.thelamberts.com\/wiki\/wp-json\/wp\/v2\/posts\/125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.thelamberts.com\/wiki\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.thelamberts.com\/wiki\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.thelamberts.com\/wiki\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.thelamberts.com\/wiki\/wp-json\/wp\/v2\/comments?post=125"}],"version-history":[{"count":3,"href":"http:\/\/www.thelamberts.com\/wiki\/wp-json\/wp\/v2\/posts\/125\/revisions"}],"predecessor-version":[{"id":128,"href":"http:\/\/www.thelamberts.com\/wiki\/wp-json\/wp\/v2\/posts\/125\/revisions\/128"}],"wp:attachment":[{"href":"http:\/\/www.thelamberts.com\/wiki\/wp-json\/wp\/v2\/media?parent=125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.thelamberts.com\/wiki\/wp-json\/wp\/v2\/categories?post=125"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.thelamberts.com\/wiki\/wp-json\/wp\/v2\/tags?post=125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}