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.ย
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
####################################################################### #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" |
Leave A Comment