# show-healthcheckstatus # # Generates a List of all VDIRs and their Healtcheck # Checks are done als Backgrpund Jobs to have a parallel check and independent of "hanging servers" # but eats up a lot of Powershell Sessions and Memory # 20170405 V2.0 Using Webrequest with a shorter Timeout instead of Backgroundjobs # Working with HTML Fragments and Files https://blogs.technet.microsoft.com/heyscriptingguy/2013/04/01/working-with-html-fragments-and-files/ # param ( $serverlist = @("EXMDB0","EXMDB1","EXMDB2","EXMDB3","EXMDB4","EXMDB5"), [array]$vdirlist = @("OWA","ECP","OAB","EWS","Autodiscover","MAPI","RPC","Microsoft-Server-ActiveSync"), [int]$updateinterval = 5, [int]$httptimeout = 2, # should not be less than 2 seconds, because Exchange takes some time sometimes [string]$htmlfile = ".\show-healthcheckstatus.html" ) write-host " Start" write-host " Servers $serverlist" write-host " VDirs $vdirlist" write-host "Start Collecting and Display Data" #$ie = new-object -ComObject "InternetExplorer.Application" write-host " Preloading Hashtable" [hashtable]$resulttable = @{} foreach ($server in $serverlist) { $resulttable[$server]= ("" | select ([array]("Server","ping")+$vdirlist)) $resulttable[$server].Server=$server } write-host " Parsing Output" while (!([console]::KeyAvailable)) { write-host " Collecting Results" foreach ($server in $serverlist) { write-host "Server=$server" -nonewline if (test-connection -computername $server -Count 2 -ErrorAction silentlycontinue) { $resulttable[$server].ping = "Up" } else { $resulttable[$server].ping = "NoPING" } foreach ($vdir in $vdirlist) { write-host " $vdir" -nonewline $testuri = "https://$server/$vdir/healthcheck.htm" $result = $null try { $result = invoke-webrequest $testuri -timeout $httptimeout } catch { write-host "=E" -nonewline $resulttable[$server].($vdir)= "NO" } if ($result) { write-host "=$($result.statuscode)" -nonewline $resulttable[$server].($vdir)= $result.statuscode } } write-host " END" } $resulttable.values | ft write-host " Send to HTML-File" [string]$htmlfilestring = "show-healthcheckstatus

show-healthcheckstatus

" $htmlfilestring+="

Last generated $(get-date)

" $htmlfilestring+= ($resulttable.values | sort-object server | convertto-html -fragment) $htmlfilestring+="" $htmlfilestring | out-file -filepath $htmlfile write-host " Wait $updateinterval Seconds. press any key to end script" start-sleep -seconds $updateinterval } write-host " End"