# show-excomponentstatus # # 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 V 1.0 Using Webrequest with a shorter Timeout instead of Backgroundjobs # 20180110 V 1.1 Ignore Certificates und variable dagname auch verwendet # Working with HTML Fragments and Files https://blogs.technet.microsoft.com/heyscriptingguy/2013/04/01/working-with-html-fragments-and-files/ # param ( $dagname = "E2016DAG1", [int]$updateinterval = 60, [string]$htmlfile = ".\show-excomponentstatus.html" ) write-host " Start" write-host " DAG-Name $dagname" Write-host "Disable Certificate checks" Add-Type @" using System; using System.Net; using System.Net.Security; using System.Security.Cryptography.X509Certificates; public class ServerCertificateValidationCallback { public static void Ignore() { ServicePointManager.ServerCertificateValidationCallback += delegate ( Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors ) { return true; }; } } "@ [ServerCertificateValidationCallback]::Ignore(); write-host "Collecting Server in DAG $dagname" $serverlist = ((Get-DatabaseAvailabilityGroup $dagname).servers).name | sort-object write-host " Total Servers in DAG: $($serverlist.count)" write-host " Preloading Hashtable" [hashtable]$resulttable = @{} write-host " Parsing Output" while (!([console]::KeyAvailable)) { write-host " Collecting Componentstatus. Be patient" foreach ($servername in $serverlist) { write-host "Server=$servername" -nonewline $componentstatus = get-ServerComponentState -identity $servername foreach ($component in $componentstatus) { $componentname = [string]($component.component) write-host " " -nonewline if(!$resulttable.containskey($componentname)) { $resulttable[$componentname]= ("" | select ([array]("Component")+ $serverlist)) $resulttable[$componentname].Component = $componentname } $resulttable[$componentname].($servername) = $component.State } write-host " END" } $resulttable.values | ft write-host " Send to HTML-File" [string]$htmlfilestring = "show-excomponentstatus

show-excomponentstatus

" $htmlfilestring+="

Last generated $(get-date)

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