Shows how to see event logs using PowerShell script & also shows how to export the event logs to html & csv file.
View Application Event logs on powershell
Get-EventLog -LogName Application
View Application Event logs with error messages
Get-EventLog -LogName Application -EntryType Error
View 10 latest Application event logs with errors
Get-EventLog -LogName Application -EntryType Error -Newest 10
View 10 latest Security event logs with Audit Failure
Get-EventLog -LogName Security -EntryType FailureAudit -Newest 10
View 10 latest System event logs with errors
Get-EventLog -LogName System -EntryType Error -Newest 10
View 10 latest Application event logs with error and export it as html file
Get-EventLog -LogName Application -EntryType Error -Newest 10 | Convertto-html c:\Applogs.htm
View 10 latest Security event logs with Audit Failure and export it to CSV file
Get-EventLog -LogName Security -EntryType FailureAudit -Newest 10 | Export-Csv -path C:\Seclogs.csv
View Event logs from a certain date and time. Set a date range and call Event logs with the date range.
$BeginDate = Get-Date -Date '12/17/2020 08:00:00'
$EndDate = Get-Date -Date '12/27/2020 17:00:00'
Get-EventLog -LogName Security -EntryType FailureAudit -After $BeginDate -Before $EndDate
Write-Output "***************************************************************************"
Get-EventLog -LogName System -EntryType Error -After $BeginDate -Before $EndDate
Write-Output "***************************************************************************"
Get-EventLog -LogName Application -EntryType Error -After $BeginDate -Before $EndDate
Write-Output "***************************************************************************"