Below is a shorted version of a script I'm against my vCenter server. All I want to change is have it color some of the cells red depending on the $f variable.
If any item fails the compliance check it will they color the cell red for easy viewing.
I don't know if this is possible it was just a request from someone. Any insight?
#------------------------------------------------------------------------------------------
$vmhost = Read-Host "Which Server do you want to run this against?"
Connect-VIServer $vmhost -credential ( Get-Credential ) | Out-Null
$p = "Pass"
$f = "Fail"
Write-Host "Checking VM Host Info Settings" -ForegroundColor "Green"
$b += @()
$b += if (Get-VM | Get-AdvancedSetting -Name "tools.guestlib.enableHostInfo" | where {$_.value -eq $false}){Get-VM | Get-AdvancedSetting -Name "tools.guestlib.enableHostInfo" | where {$_.value -eq $false} |
Select-Object -Property @{n='VM';e={$_.Entity}},
@{n='Value';e={$_.Value}},
@{n='Result';e={$p}} | ConvertTo-Html -Fragment -PreContent "<h4>VM Host Info Setting: Passes</h4>" | Out-String}
$b += if (Get-VM | Get-AdvancedSetting -Name "tools.guestlib.enableHostInfo" | where {$_.value -eq $true}){Get-VM | Get-AdvancedSetting -Name "tools.guestlib.enableHostInfo" | where {$_.value -eq $true} |
Select-Object -Property @{n='VM';e={$_.Entity}},
@{n='Value';e={$_.Value}},
@{n='Result';e={$f}} | ConvertTo-Html -Fragment -PreContent "<h4>VM Host Info Setting: Fails</h4>" | Out-String}
Write-Host "Compliance Check Complete" -ForegroundColor "Green"
Write-Host
Write-Host
$head = @'
<style>
body { background-color:#zzzzzz;
font-family:Tahoma;
font-size:12pt; }
td, th { border:1px solid black;
border-collapse:collapse; }
th { color:white;
background-color:black; }
table, tr, td, th { padding: 2px; margin: 0px }
table { margin-left:50px; }
</style>
'@
ConvertTo-HTML -head $head -PostContent $b -Body "<h1>Compliance Check for $vmhost</h1>" | Out-File C:\Compliance\$vmhost.htm