Power ShellWindows Server

Event Log HTML Report

I created this script which create an event log report and export as html format

<#
.Synopsis
   Get Event Log reports in HTML FOrmat
.DESCRIPTION
   This script design to get the report of any type of EventViewer log and display the report in HTML format.
.EXAMPLE
   get-log -Computername localhost -log system -newest 1000 -path c:\report.html

#>

function get-log {

    [cmdletbinding()]

    param (
     [Parameter(Mandatory=$true)]
     [string]$log = "system",
     [string]$Computername = $env:computername,
     [int32]$Newest = 500,
     [String]$ReportTitle = "Event Log Report",
     
     [String]$path

    )

    #get event log data and group it
    $data = Get-EventLog system -EntryType Error -Newest $Newest -ComputerName $Computername |
    Group-Object -Property Source -NoElement


    #Create HTML Report
    $footer = "<h5><i>report run $(get-date)</i></h5>"
    $css = "c:\design.css"
    $precontent = "<h1>$Computername</h1><h2> Last $newest error sources from $log </h2>"


    $data | Sort-Object -Property count, name -Descending |
        Select-Object Count, Name |
        ConvertTo-Html -Title $ReportTitle -PreContent $precontent -PostContent $footer -CssUri $css |
        Out-File -FilePath $path |
        invoke-item


}

 

Add this CSS design to your script, first save it as design.css

@charset “UTF-8″;
table{font-family:”Trebuchet MS”, Arial, Helvetica, sans-serif;border-collapse:collapse;}td {font-size:1em;border:1px solid #98bf21;padding:5px 5px 5px 5px;}th {font-size:1.1em;text-align:center;padding-top:5px;padding-bottom:5px;padding-right:7px;padding-left:7px;background-color:#A7C942;color:#ffffff;}name tr{color:#000000;background-color:#EAF2D3;}

 

Show More

Related Articles

Leave a Reply

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

Back to top button