So, Internet Denizens,

I come to you today with my second part of my script. It basically uses the aforementioned HTMLTable.psm1 and creates fancy tables in an HTML document that is color coded.

If you are interested, I can do some tutorial stuff about how to make it work, but I’m sure if you are a reader of this, you probably are used to this sort of stuff and can figure it out.

function New-HTMLReport {
    Param(
    $mRSHealth,
    $assistHealth,
    $mAPIHealth,
    $replHealth,
    $mailFlowHealth,
    $sMTPHealth,
    $replStatus,
    $calConnect,
    $ecpConn,
    $imapConn,
    $popHealth,
    $serviceHealth,
    $outlookAnyHealth,
    $mAPIHttpHealth,
    $actSyncHealth,
    $date,
    $serverType,
    $serverName
    )
    #Mailbox Replication Service Health
    if($mRSHealth) {
        $mRSTable = $mRSHealth | select Check,Passed,Message| New-HTMLTable -setAlternating $false |
            Add-HTMLTableColor -Argument "True" -Column "Passed" -AttrValue "background-color:#00ff00" | 
            Add-HTMLTableColor -Argument "False" -Column "Passed" -AttrValue "background-color:#ff0000"
        }

    #Mailbox Assistant Health
    if($assistHealth) {
        $assistObj = New-OBject -TypeName PSObject
        $assistObj | Add-Member -MemberType NoteProperty -Name EventType -Value $assistHealth.Events.EventType
        $assistObj | Add-Member -MemberType NoteProperty -Name EventMessage -Value $assistHealth.Events.EventMessage
        $assistTable = $assistObj | New-HTMLTable |
            Add-HTMLTableColor -Argument "Information" -Column "EventType" -AttrValue "background-color:#00ff00" |
            Add-HTMLTableColor -Argument "Warning" -Column "EventType" -AttrValue "background-color:#ffff00" | 
            Add-HTMLTableColor -Argument "Error" -Column "EventType" -AttrValue "background-color:#ff0000"
        }

    #MAPI Connectivity Health
    if($mAPIHealth) {
        $mAPITable = $mAPIHealth | select Database,Result,Error | New-HTMLTable -setAlternating $false |
            Add-HTMLTableColor -Argument "*FAILURE*" -Column "Result" -AttrValue "background-color:#ff0000" | 
            Add-HTMLTableColor -Argument "Success" -Column "Result" -AttrValue "background-color:#00ff00"
        }

    #Replication Health
    if($replHealth) {
        $replTable = $replHealth | select Check,Result,Error | New-HTMLTable -setAlternating $false |
            Add-HTMLTableColor -Argument "*FAILED*" -Column "Result" -AttrValue "background-color:#ff0000" | 
            Add-HTMLTableColor -Argument "Passed" -Column "Result" -AttrValue "background-color:#00ff00"
        }

    #Mailflow Testing
    if($mailFlowHealth) {
        $mailFlowTable = $mailFlowHealth | select TestMailflowResult,MessageLatencyTime,IsRemoteTest | New-HTMLTable |
            Add-HTMLTableColor -Argument "*FAILURE*" -Column "TestMailflowResult" -AttrValue "background-color:#ff0000" |
            Add-HTMLTableColor -Argument "Success" -Column "TestMailflowREsult" -AttrValue "background-color:#00ff00"
        }

    #Receive Connector Health
    if($sMTPHealth) {
        $sMTPTable = $sMTPHealth | select ReceiveConnector,EndPoint,StatusCode | New-HTMLTable | 
            Add-HTMLTableColor -Argument "*FAILURE*" -Column "StatusCode" -AttrValue "background-color:#ff0000" |
            Add-HTMLTableColor -Argument "Success" -Column "StatusCode" -AttrValue "background-color:#00ff00"
        }

    #Replication Status Table
    if($replStatus) {
        #Creating Params for copy queue length
        $params = @{
            Column = "CopyQueueLength"
            ScriptBlock = { [double]$args[0] -gt [double]$args[1] }
            }
        $replstatusTable = $replStatus | select Name,Status,CopyQueueLength,ContentIndexState | New-HTMLTable |
            Add-HTMLTableColor -Argument "Dismounted" -Column "Status" -AttrValue "background-color:#ff0000" |
            Add-HTMLTableColor -Argument "Mounted" -Column "Status" -AttrValue "background-color:#00ff00" |
            Add-HTMLTableColor -Argument "Failed" -Column "ContentIndexState" -AttrValue "background-color:#ff0000" |
            Add-HTMLTableColor -Argument "Healthy" -Column "ContentIndexState" -AttrValue "background-color:#00ff00" 
        $replstatusTable = Add-HTMLTableColor -HTML $replstatusTable -Argument 50 -AttrValue "background-color:#ffff00" @params
        $replstatusTable = Add-HTMLTableColor -HTML $replstatusTable -Argument 100 -AttrValue "background-color:#ff0000" @params
        }

    #Calendar Connectivity
    if($calConnect) {
        $calendarTable = $calConnect | select Scenario,Result,Latency,Error | New-HTMLTable |
            Add-HTMLTableColor -Argument "Skipped" -Column "Result" -AttrValue "background-color:#ffff00" |
            Add-HTMLTableColor -Argument "Success" -Column "Result" -AttrValue "background-color:#00ff00" |
            Add-HTMLTableColor -Argument "Failure" -Column "Result" -AttrValue "background-color:#ff0000"
        }

    #Exchange Control Panel Connectivity
    if($ecpConn) {
        $ecpConnTable = $ecpConn | select Scenario,Result,Latency,Error | New-HTMLTable |
            Add-HTMLTableColor -Argument "Skipped" -Column "Result" -AttrValue "background-color:#ffff00" |
            Add-HTMLTableColor -Argument "Success" -Column "Result" -AttrValue "background-color:#00ff00" |
            Add-HTMLTableColor -Argument "Failure" -Column "Result" -AttrValue "background-color:#ff0000"
        }

    #IMAP Info
    if($imapConn) {
        $imapConnTable = $imapConn | select Scenario,Result,Latency,Error | New-HTMLTable |
            Add-HTMLTableColor -Argument "Skipped" -Column "Result" -AttrValue "background-color:#ffff00" |
            Add-HTMLTableColor -Argument "Success" -Column "Result" -AttrValue "background-color:#00ff00" |
            Add-HTMLTableColor -Argument "Failure" -Column "Result" -AttrValue "background-color:#ff0000"
        }

    #POP3 Health
    if($popHealth) {
        $popHealthTable = $popHealth | select Scenario,Result,Latency,Error | New-HTMLTable |
            Add-HTMLTableColor -Argument "Skipped" -Column "Result" -AttrValue "background-color:#ffff00" |
            Add-HTMLTableColor -Argument "Success" -Column "Result" -AttrValue "background-color:#00ff00" |
            Add-HTMLTableColor -Argument "Failure" -Column "Result" -AttrValue "background-color:#ff0000"
        }

    #Service Health
    if($serviceHealth) {
        $serviceHealthTable = $serviceHealth | select Role,RequiredServicesRunning,ServicesRunning,ServicesNotRunning | New-HTMLTable |
            Add-HTMLTableColor -Argument "True" -Column "RequiredServicesRunning" -AttrValue "background-color:#00ff00" | 
            Add-HTMLTableColor -Argument "False" -Column "RequiredServicesRunning" -AttrValue "background-color:#ff0000"
        }

    #Outlook Anywhere Health Check
    if($outlookAnyHealth) {
        $outlookAnyHealthTable = $outlookAnyHealth | select MonitorIdentity,ResultType,Error | New-HTMLTable | 
            Add-HTMLTableColor -Argument "Succeeded" -Column "ResultType" -AttrValue "background-color:#00ff00" |
            Add-HTMLTableColor -Argument "Failed" -Column "ResultType" -AttrValue "background-color:#ff0000"
        }

    #MAPI over HTTP Health Check
    if($mAPIHttpHealth) {
        $mAPIHttpHealthTable = $mAPIHttpHealth | select MonitorIdentity,ResultType,Error | New-HTMLTable | 
            Add-HTMLTableColor -Argument "Succeeded" -Column "ResultType" -AttrValue "background-color:#00ff00" |
            Add-HTMLTableColor -Argument "Failed" -Column "ResultType" -AttrValue "background-color:#ff0000"
        }

    #ActiveSync Health Check
    if($actSyncHealth) {
        $actSyncHealthTable = $actSyncHealth | select Scenario,Result,Latency,Error | New-HTMLTable |
            Add-HTMLTableColor -Argument "Success" -Column "Result" -AttrValue "background-color:#00ff00" | 
            Add-HTMLTableColor -Argument "Failure" -Column "Result" -AttrValue "background-color:#ff0000"
        }

    #Building HTML Report
    $HTML = New-HTMLHead
    if($mRSTable) {
        $HTML += "<h3>Mailbox Replication Health Checks</h3>"
        $HTML += $mRSTable
        }
    if($assistTable) {
        $HTML += "<h3>Mailbox Assistant Health Checks</h3>"
        $HTML += $assistTable 
        }
    if($mAPITable) {
        $HTML += "<h3>MAPI Health Checks</h3>"
        $HTML += $mAPITable
        }
    if($replTable) {
        $HTML += "<h3>Replication Health Checks</h3>"
        $HTML += $replTable 
        }
    if($mailFlowTable) {
        $HTML += "<h3>Mailflow Testing Checks</h3>"
        $HTML += $mailFlowTable
        }
    if($sMTPTable) {
        $HTML += "<h3>ReceiveConnector Health Checks</h3>"
        $HTML += $sMTPTable 
        }
    if($replstatusTable) {
        $HTML += "<h3>Current Replication Status Checks</h3>"
        $HTML += $replstatusTable
        }
    if($calendarTable) {
        $HTML += "<h3>Calendar Health Checks</h3>"
        $HTML += $calendarTable
        }
    if($ecpConnTable) {
        $HTML += "<h3>Exchange Control Panel Health Checks</h3>"
        $HTML += $ecpConnTable
        }
    if($imapConnTable) {
        $HTML += "<h3>IMAP Health Checks</h3>"
        $HTML += $imapConnTable
        }
    if($popHealthTable) {
        $HTML += "<h3>POP3 Health Checks</h3>"
        $HTML += $popHealthTable
        }
    if($serviceHealthTable) {
        $HTML += "<h3>Service Health Checks</h3>"
        $HTML += $serviceHealthTable
        }
    if($outlookAnyHealthTable) {
        $HTML += "<h3>Outlook Anywhere RPC over HTTP Health Checks</h3>"
        $HTML += $outlookAnyHealthTable
        }
    if($mAPIHttpHealthTable) {
        $HTML += "<h3>MAPI over HTTP Health Checks</h3>"
        $HTML += $mAPIHttpHealthTable
        }
    if($actSyncHealthTable) {
        $HTML += "<h3>ActiveSync Health Checks</h3>"
        $HTML += $actSyncHealthTable 
        }
    $HTML += "<h3>End of Report</h3>" | Close-HTML

    Out-File .\Results$date\$serverType\$serverName.\Report.htm
    Set-Content .\Results$date\$serverType\$serverName\Report.htm $HTML 

    }
Expand

Without further Ado!

Now a couple things you will notice, first, I set everything up in if() statements so that it could be modular. Basically you call this exact same script for the CAS role as you do for the Mailbox, this same thing will be used for E14, and E12. If there are tests that you feel like I should have covered, but didn’t, you can add them yourself. The key thing to note is how the colors are made, you use the keyword ‘column’ for specifying the attribute name, and -argument for the actual value of that column. The AttrValue is just a place to put the color you want.

Additionally you’ll see a specific section that does some stuff to the Replication Status, specifically it adds colors for copy queue length, giving you a yellow and a red at different lengths. One of the key takeaways here (Especially for future scripts) is that you can pass the same variable (In this case $replstatusTable) and it will just append at the end if you pass the argument -HTML. This allows you to take loops through your table and do something like if then statements. It is a really snazzy tool that… Cookie.Monster, came up with, I really like it.

Anyway, that’s all for today! I’ll be following up soon™ with the final section which goes into how to make it all work.

Leave a Reply

Your email address will not be published. Required fields are marked *