Monday, May 19, 2014

Test-ActiveSyncConnectivity power shell script to validate the errors in Exchange Active Sync connectivity

# Test-ActiveSyncConnectivity
# Developed by Babu Dhinakaran S
# To execute from within NSClient++
#
#NSClient 0.4.1.90
#[/settings/external scripts/scripts]
#ps2 = cmd /c echo scripts\\test.ps1 | PowerShell.exe -command -

# On the check_nrpe command include the -t 30, since it takes some time to load the Exchange cmdlet's.

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010

#Add-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.E2010



[int[]]$NagiosStatus = 0
$NagiosDescription = ""
$sValue = New-Object System.Collections.ArrayList
$rValue = New-Object System.Collections.ArrayList
$lValue = New-Object System.Collections.ArrayList
$eValue = New-Object System.Collections.ArrayList
$i=0

               
ForEach ($content in Test-ActiveSyncConnectivity -TrustAnySSLCertificate -ClientAccessServer shs-cas-p1)
 {            
  # ForEach content Handle the Scenario, Result, Latency and Error
  $sv=$content.Scenario
  $rv=$content.Result
  $lv=$content.Latency
  $ev=$content.Error
  $s_Value = $sValue.Add("$sv")
  $r_Value = $rValue.Add("$rv")
  $l_Value = $lValue.Add("$lv")
  $e_Value = $eValue.Add("$ev")
 }

#Write-Host "Before Any Operation:"
#Write-Host $sValue.Count
#Write-Host $sValue
#Write-Host $rValue.Count
#Write-Host $rValue
#Write-Host $lValue.Count
#Write-Host $lValue
#Write-Host $eValue.Count
#Write-Host $eValue
[String[]] $rcontent

ForEach ($rcontent in $rValue)
{
if ($rcontent -notcontains "Success")
{
#Write-Host "$i th Position:" $i
$NagiosStatus = 2
$NagiosDescription = $NagiosDescription + $sValue[$i] + ":" + $eValue[$i]

}
     $i++
}


# Output, what level should we tell our caller?
if ($NagiosStatus -eq 2) {
                Write-Host "CRITICAL: Test-ActiveSyncConnectivity is in error:" $NagiosDescription
exit 2

} else {
                Write-Host "OK: All Result Success for Test-ActiveSyncConnectivity."
exit 0
}