Continuing on with my daily status email series; after displaying event log information, my email displays a high level summary of the virtual machine health:
These tables are generated with the following code:
# VM Health
$message = $message + ""
$message = $message + "Virtual Machine Health
"
$message = $message + "Virtual Machine Health:
" + ((Get-VM | `
Select-Object @{Expression={$_.Name};Label="Name"}, `
@{Expression={$_.State};Label="State"}, `
@{Expression={$_.Status};Label="Operational Status"}, `
@{Expression={$_.UpTime};Label="Up Time"} `
| ConvertTo-HTML -Fragment) `
| %{if($_.Contains("Operating normally ")){$_.Replace("", " background-color:$($warningColor)`"> ")}else{$_}} ` | %{if($_.Contains("Running Operating normally ")){$_.Replace("background-color:$($warningColor)`"> ", " background-color:$($tableColor)`"> ")}else{$_}}) ` + "
"# VM Replication Health
$message = $message + ""
$message = $message + "Virtual Machine Replication Health
"$message = $message + "Virtual Machine Replication Health:
" + ((Get-VM | `Select-Object @{Expression={$_.Name};Label="Name"}, `
@{Expression={$_.ReplicationState};Label="State"}, `
@{Expression={$_.ReplicationHealth};Label="Health"}, `
@{Expression={$_.ReplicationMode};Label="Mode"} `
| ConvertTo-HTML -Fragment) `| %{if($_.Contains("Replicating Normal ")){$_.Replace("", " background-color:$($tableColor)`"> ")}else{$_}}) ` + "
"Both of these tables are generated by taking the output of “Get-VM” and displaying different information.
Notes about this code:
- Once again - I use raw HTML to set the color of the table headers.
- Again - I run the output of these commands through Select-Object with the use of the “Expression” option to set column labels appropriately.
- Again - I use ConvertTo-HTML –Fragment to get a nice HTML table outputted.
- This time I do something different to get color coding for individual entries in the table. I actually set each table cell to be “red��� by default. I then do some string parsing to see if the health is good – and switch the background color if I get a positive result. The reason why I use this approach is that the list of “known good states” is much smaller than the list of “known bad states”.
Cheers,
Ben