Forum Discussion

Sekhar7590's avatar
Sekhar7590
Copper Contributor
Jul 02, 2020

Create a htmt report with color

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
    • hkarthik_7's avatar
      hkarthik_7
      Copper Contributor

      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

Resources