Create a htmt report with color

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
Could anyone can help me with this scenario

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 = "
 <BODY background-color:peachpuff>
    <font color =""#B03A2E"" face=""Microsoft Tai le"">
 <Table border=1 cellpadding=3 cellspacing=3><br>
 <TR bgcolor=#A9CCE3 align=center>
 <TD><B>Start Time</B></TD>
 <TD><B>Paged Memory Size</TD></B>
 <TD><B>Virtual Memory Size</TD></B>
 <TD><B>Virtual Memory Size 64</TD></B>
#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