# HTML Conditaional formatting

**URL:** <https://forums.powershell.org/t/html-conditaional-formatting/7558>\
**Category:** PowerShell Help\
**Created:** [November 19, 2016, 12:21pm UTC](https://forums.powershell.org/t/html-conditaional-formatting/7558 "2016-11-19T12:21:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bishwabid](https://avatars.discourse-cdn.com/v4/letter/b/977dab/32.png) [@bishwabid](https://forums.powershell.org/u/bishwabid)\
**Post date:** [November 19, 2016, 12:21pm UTC](https://forums.powershell.org/t/html-conditaional-formatting/7558/1 "2016-11-19T12:21:51Z")

</div>

```
Function Get-Diskinfo { 
Clear-Content "c:\Scripts\comps.txt" 
Clear-Content "C:\Users\administrator.CONTOSO\Desktop\UnreachableHosts.txt"
[System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().domains.DomainControllers.Name | Out-File "c:\Scripts\comps.txt"  
$computername = Get-Content "c:\Scripts\comps.txt" -ReadCount 0 
$ErrorActionPreference = "Stop"
foreach ($computer in $computername) 
{ 
Try{
Get-WmiObject Win32_LogicalDisk -filter "DriveType=3" -computer $computer | 
Select SystemName,DeviceID,@{Name="Size(GB)"; 
Expression={"{0:N1}" -f($_.size/1gb)}},@{Name="FreeSpace(GB)"; 
Expression={"{0:N1}" -f($_.freespace/1gb)}},@{Name="LOW SPACE"; 
Expression={"{0:N1}" -f($_.freespace / $_.size -lt .2)}}  
 }
Catch 
{
Add-Content "$computer is not reachable" -path C:\Users\administrator.CONTOSO\Desktop\error.txt
}
}}  
$a = ""
$a = $a + "BODY{background-color:#95B9C7;font-family:Calibri;font-size:10pt;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}"
$a = $a + ""
Get-Diskinfo | ConvertTo-HTML -Head $a | out-file c:\Scripts\DCs.htm
```

Above code is working fine. Want to add Color Red when False becomes True on Lowspace.

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [November 19, 2016, 12:26pm UTC](https://forums.powershell.org/t/html-conditaional-formatting/7558/2 "2016-11-19T12:26:39Z")

</div>

I’d suggest looking at our free eBook, “Creating HTML Reports in PowerShell.” I wrote a module that makes this kind of conditional formatting easier, and the ebook contains an example of exactly that. You’ll also have to do a lot less manual HTML creation like you’re doing - my module handles most of it, with a lot of dynamic display options.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:39pm UTC](https://forums.powershell.org/t/html-conditaional-formatting/7558/3 "2024-05-16T20:39:52Z")

</div>

Closed on May 16, 2024, 8:39pm UTC


