Hi Guys,
Looking for some help or ideas on how to create a function that will allow to get event log information. See below on the requirements
This is to be used for my HTML Powershell report as I’m wanting to convertto-HTML the following
ComputerName variable, Logname (normally application, system or security), Type and from the last hour, 24 hours and week.
param([string]$ComputerName ,
[HashTable]$data,
[string]$LogName,
[string]$EntryInfo = "Information",
[string]$EntryWarn = "Warning",
[string]$EntrError = "Error",
[int]$LastHour = (Get-Date).AddHours(-1),
[int]$LastDay = (Get-Date).AddHours(-24),
[int]$LastWeek = (Get-Date).AddDays(-7)
)
try
{
$data = @()
$Events = Get-EventLog -ComputerName $computername -LogName $LogName -EntryType $EntryError,$EntryWarn,$EntryInfo -After (Get-Date).AddHours(-1) -ErrorAction STOP -Verbose
foreach ($event in $Events) {
$row = [PSCustomObject]@{
'Date/Time' = $event.TimeWritten
'EventID' = $event.EventID
'Message' = $event.Message
'Source' = $event.Source
'Entry Type' = $event.EntryType
}
$data += $row