Creating Multiple Tables in single HTML Report using Powershell

Actually System Admins do a lot stuff with Powershell Scripts. Often in Powershell you get lists where data is collected in table format. All Tech/non Tech peoples loves a nice HTML report for reviewing. Creating these type of reports in PowerShell is very easy and simple with Powershell . These type of nice HTML reports can be generate with the help ConvertTo-HTML cmdlet.  Converts Microsoft .NET Framework objects into HTML that can be displayed in a Web browser. The Powershell based Reports are easy to create  and you also can create a unique .css file to make the design for all reports identically to impress with reports.

In my previous article i had posted the article which helps to create single HTLML report. Here i going to deep drive about how to populate multiple reports in single HTML format.

Create CSS File

Here i had wrote the required CSS code for the report and placed the below code in notepad and saved with the name C:\dotnet-helpers\Logreport.css. If required you can create two separate .css file and design your reports based on your requirements. 

body {
  font-family: Monospace;
  font-size: 10pt;
}
table,td, th {
  border: 1px solid black;
}
th {
  color: #00008B;
  background-color: white;
  font-size: 12pt;
}
table {
  margin-left: 30px;
}
h2 {
  font-family: Tahoma;
  color: #6D7B8D;
}
h1 {
  color: #DC143C;
}
h5 {
  color: #c7bc07;
  font-size: 10pt;
}

In the below script, I had creating two separate variable to assign the Application and System Event logs ( $applicationLog ,$systemLog). Here you can get detail post about the Event log, so refer if required more details on it.

Then you can refer the stylesheet from an external CSS file with help of -CssUri parameter (-CssUri ‘C:\dotnet-helpers_com\Logreport.css’) and generate the HTML report in the destination location. The CSS  file will applied to the HTML element during the execution and generate the report.

#######################################################################
#Project : Creating Powershell Mulitple Reports in HTML with CSS Format
#Developer : Thiyagu S (dotnet-helpers.com)
#Tools : PowerShell 5.1.15063.1155 
#E-Mail : mail2thiyaguji@gmail.com 
######################################################################
 
$applicationLog = Get-EventLog -LogName Application -Newest 5| Select-Object -Property Source, EventID, InstanceId  
convertto-html -Title "Daily Log Report"-PreContent"<H1>Daily Event Applicaton Log Report</H1>" -PostContent "<H5><i>Copy right @ dotnet-helpers.com</i></H5>" -CSSUri "C:\dotnet-helpers_com\Logreport.css"
 
$systemLog = Get-EventLog -LogName System -Newest 5 | Select-Object -Property Source, EventID, InstanceId| 
convertto-html -Title "Daily Log Report" -PreContent "<H1>Daily Event Server Log Report</H1>" -PostContent "<H5><i>Copy right @ dotnet-helpers.com</i></H5>" -CSSUri "C:\Thiyagu Disk\Logreport.css"
 
 
ConvertTo-HTML -body "$applicationLog $systemLog"  | Set-Content "C:\dotnet-helpers_com\EventLogReport.html"

OUTPUT

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.