HTML/CSS Help with Powershell Scripts

Welcome Forums General PowerShell Q&A HTML/CSS Help with Powershell Scripts

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

 
Participant
1 month, 1 week ago.

  • Author
    Posts
  • #122654

    Participant
    Points: 4
    Rank: Member

    So my code looks like this. My question is I'm trying to find a way to add color highlights to certain cells. So for example in the Test-MemoryUsage function the script will produce information about the server printing out the Total Size and the Percent Free. I would like to able to add a style where if the Percent free is less than a number then it will highlight more so red and if it is in good standing then it will highlight green.

    function Get-DataSheet{
         [CmdletBinding()]
        param (
                
                )
    	
        Begin{}
    
    	Process{
                     $frag5 = Test-MemoryUsage | convertto-html -Fragment -PreContent '

    Memory Usage

    ' | Out-String $head = @' '@ convertto-html -head $head -PostContent $frag1,$frag2,$frag3,$frag4,$frag5,$frag6,$frag7,$frag8,$frag9 -PreContent '

    Data Collection Sheet

    ' | out-file C:\Data.html Invoke-Item "C:\Data.html" #Open the document. } End{} }
  • #122663

    Participant
    Points: 333
    Helping Hand
    Rank: Contributor

    When you start getting beyond basic HTML + CSS using ConvertTo-HTML, you'll need to do a loop and manually generate the html code adding style tags or another options is using some fun methods like this:

    https://stackoverflow.com/questions/4559233/technique-for-selectively-formatting-data-in-a-powershell-pipeline-and-output-as/4617379#4617379

You must be logged in to reply to this topic.