Skip to content

Instantly share code, notes, and snippets.

@theeye-io
Last active November 25, 2016 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theeye-io/ed1f2407b3d3aae90a69af064c3e204a to your computer and use it in GitHub Desktop.
Save theeye-io/ed1f2407b3d3aae90a69af064c3e204a to your computer and use it in GitHub Desktop.
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