HTML Conditaional formatting

Welcome Forums General PowerShell Q&A HTML Conditaional formatting

This topic contains 1 reply, has 2 voices, and was last updated by

2 years, 6 months ago.

  • Author
  • #58226

    Topics: 1
    Replies: 0
    Points: 0
    Rank: Member
    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) 
    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)}}  
    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.

  • #58228

    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    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.

The topic ‘HTML Conditaional formatting’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort