Saturday, February 4, 2017

Powershell Scripting: Testing email queues and provide notification for large queues

This is a guest post  Mr. Troy Collins
<# 
This script will test Exchange mail queues and e-mail if amount of message are too many.
Writen by Troy Collin
#>

$server = hostname

#$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri
http://$server/powershell/  -Authentication Kerberos
#Import-PSSession $Session
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
Write-host "Exchange Snapin now enabled."

$total_messages = get-transportserver| get-queue |  foreach -begin {$total=0} -process {$total+=$_.messageCount} -end {$total}
if ($total_messages -gt 200)
{
write-host "messages are high"
$total_messages
$message = "`n*******Automated E-mail DO NOT REPLY******`n
Exchange Message Queues test. `n
`n Script runs from scheduled task on $server (mailqueues.check) `n
location of script is C:\Scripts\Queue.Check\queue.check.ps1`n

`n`nAlert Check message queue!!
current total is $total_messages`n `n

No comments:

Post a Comment