Created
May 12, 2021 11:12
-
-
Save padmick/a30d69eee1fbdf7558455ed51620aa24 to your computer and use it in GitHub Desktop.
Exporting event logs to excel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Set-Variable -Name EventAgeDays -Value 1 #we will take events for the last one days, can bump later if needed | |
Set-Variable -Name CompArr -Value @("SERV1") # where it says serv1 replace with your PC name | |
Set-Variable -Name LogNames -Value @("Application", "System") # Checking app and system logs | |
Set-Variable -Name EventTypes -Value @("Error", "Warning") # Loading only Errors and Warnings | |
Set-Variable -Name ExportFolder -Value "C:\TEST\" | |
$el_c = @() #consolidated error log | |
$now=get-date | |
$startdate=$now.adddays(-$EventAgeDays) | |
$ExportFile=$ExportFolder + "el" + $now.ToString("yyyy-MM-dd---hh-mm-ss") + ".csv" # we cannot use standard delimiteds like ":" | |
foreach($comp in $CompArr) | |
{ | |
foreach($log in $LogNames) | |
{ | |
Write-Host Processing $comp\$log | |
$el = get-eventlog -ComputerName $comp -log $log -After $startdate -EntryType $EventTypes | |
$el_c += $el #consolidating | |
} | |
} | |
$el_sorted = $el_c | Sort-Object TimeGenerated #sort by time | |
Write-Host Exporting to $ExportFile | |
$el_sorted|Select EntryType, TimeGenerated, Source, EventID, MachineName | Export-CSV $ExportFile -NoTypeInfo #EXPORT | |
Write-Host Done! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment