Instantly share code, notes, and snippets.

Embed
What would you like to do?
CheckExchangeMailQueue2013
#
# copied some parts of this script from
# https://gallery.technet.microsoft.com/office/e0bb250e-e699-4c6c-a5be-f1af245a2219
#
#$queueThreshold=$args[0]
$queueThreshold=50
#$domainUser=$args[1]
#$domainUser=
#$s = New-PSSession -Credential domain\user
#Import-PSSession $s
#Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2013
. 'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'
Connect-ExchangeServer -auto
#Get-Queue -identity submission
$MessageCount = Get-Queue | foreach -begin {$total=0} -process {$total+=$_.messageCount} -end {$total}
Write-Host $MessageCount
if ([int]$MessageCount -gt [int]$queueThreshold){
$out = @{state="failure";data=@{message_count=$MessageCount}}
} else {
$out = @{state="success";data=@{message_count=$MessageCount}}
}
$json = $out | ConvertTo-Json -Compress
Write-Host $json
Exit 0
# runas
powershell.exe -NonInteractive -ExecutionPolicy ByPass -File "%script%"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment