FeaturedPower ShellScripts

Get-EventLog Reports

<#
.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


}

 

Show More

Related Articles

Back to top button