Create a htmt report with color

%3CLINGO-SUB%20id%3D%22lingo-sub-1502532%22%20slang%3D%22en-US%22%3ECreate%20a%20htmt%20report%20with%20color%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1502532%22%20slang%3D%22en-US%22%3EHi%20team%2C%3CBR%20%2F%3E%3CBR%20%2F%3EI%20need%20to%20create%20a%20html%20report%20with%20running%20processes%20with%20start%20time%3CBR%20%2F%3ECondition%3A%20if%20start%20time%20is%20more%20than%205%20hours%20then%20highlight%20with%20red%20color%20in%20report%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1502532%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Highlighted
New Contributor
Hi team,

I need to create a html report with running processes with start time
Condition: if start time is more than 5 hours then highlight with red color in report
2 Replies
Highlighted
Could anyone can help me with this scenario
Highlighted

Hi @Sekhar7590, you can save the below script in a .ps1 file and run it. This spits the output to a html file and highlights all processes which are running for more than 5 hours in red.

 

Hope this helps.

 

 #region build html report
 $Html = "
 <HTML>
 <TITLE> LONG RUNNING PROCESSES </TITLE>
 <BODY background-color:peachpuff>
    <font color =""#B03A2E"" face=""Microsoft Tai le"">
    <H1> LONG RUNNING PROCESSES </H1>
 </font>
 <Table border=1 cellpadding=3 cellspacing=3><br>
 <TR bgcolor=#A9CCE3 align=center>
 <TD><B>Name</B></TD>
 <TD><B>Start Time</B></TD>
 <TD><B>Id</B></TD>
 <TD><B>Paged Memory Size</TD></B>
 <TD><B>Virtual Memory Size</TD></B>
 <TD><B>Path</TD></B>
 <TD><B>CPU</TD></B>
 <TD><B>Virtual Memory Size 64</TD></B>
 </TR> 
 "
#endregion build html report

# detect processes running more than 5 hours
foreach ($proc in (Get-Process)) {
    $Html += "<TR><TD align='center' >$($proc.Name)</TD>"
    If($proc.StartTime -lt (Get-Date).AddHours(-5)) {
        $Html += "<TD align='center' bgcolor=#EC7063>$($proc.StartTime)</TD>"
    } else {
        $Html += "<TD align='center'>$($proc.StartTime)</TD>"
    }
    $Html += "<TD align='center' >$($proc.Id)</TD>"
    $Html += "<TD align='center' >$($proc.PagedMemorySize)</TD>"
    $Html += "<TD align='center' >$($proc.VirtualMemorySize)</TD>"
    $Html += "<TD align='center' >$($proc.Path)</TD>"
    $Html += "<TD align='center' >$($proc.CPU)</TD>"
    $Html += "<TD align='center' >$($proc.VirtualMemorySize64)</TD>"
}

# save the report in current directory
$Html | Out-File .\proc.html