I am trying to create a script that hostmon can use to get the amount of email in a submission queue. I just need it to return the results of “get-queue submission | select messagecount�. If the result is over 100 send a alert. Can you assist me, I cannot figure out how to script this in your program.
Requirements
Server parameter
Script
Need to return the numerical value
Powershell exchange 2013 submission queue
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact:
You need to use Shell Script test method: http://www.ks-soft.net/hostmon.eng/mfra ... m#chkShell
Script for Shell Script test may look like the following:
Start cmd: C:\Windows\sysnative\WindowsPowerShell\v1.0\powershell.exe %script% %params%
Script requires 1 parameter - message count threshold
Script for Shell Script test may look like the following:
Code: Select all
$statusUnknown = "ScriptRes:Unknown:"
$statusOk = "ScriptRes:Ok:"
$statusBad = "ScriptRes:Bad:"
if ($args.Count -ne 1) {
echo $statusUnknown"Message count threshold is required"
exit
}
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
[int]$msgLimit = $args[0]
[int]$msgCnt = $(get-queue submission).MessageCount
if ($msgCnt -gt $msgLimit)
{
echo $statusBad$msgCnt
}
else
{
echo $statusOk$msgCnt
}
Script requires 1 parameter - message count threshold
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact:
Improved script (with exception handling):
Start cmd: C:\Windows\sysnative\WindowsPowerShell\v1.0\powershell.exe %script% %params%
Script requires 1 parameter - message count threshold
Code: Select all
$statusUnknown = "ScriptRes:Unknown:"
$statusOk = "ScriptRes:Ok:"
$statusBad = "ScriptRes:Bad:"
if ($args.Count -ne 1) {
echo $statusUnknown"Message count threshold is required"
exit
}
Try
{
Add-PSSnapin Microsoft.Exchange.*
[int]$msgLimit = $args[0]
[int]$msgCnt = $(Get-Queue -Identity submission).MessageCount
} catch {
echo $statusUnknown$_.Exception.Message
Break
}
if ($msgCnt -gt $msgLimit)
{
echo $statusBad$msgCnt
}
else
{
echo $statusOk$msgCnt
}
Script requires 1 parameter - message count threshold