Created
August 17, 2017 20:51
-
-
Save jeffpatton1971/f7875a6317e0c3ae4d905a4ab9d74396 to your computer and use it in GitHub Desktop.
A script that will pull the logs from Windows that have records, between the dates specified.
This file contains hidden or 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
param | |
( | |
$StartDate = (Get-Date), | |
$EndDate = (Get-Date) | |
) | |
try | |
{ | |
$ErrorActionPreference = 'Stop'; | |
$Error.Clear(); | |
$ActiveLogs = Get-WinEvent -ListLog * |Where-Object {$_.RecordCount -gt 0}; | |
foreach ($Log in $ActiveLogs) | |
{ | |
Write-Output "Processing : $($Log.LogName)"; | |
$ThisLog = Get-WinEvent -LogName $Log.LogName |Where-Object {(Get-Date($_.TimeCreated)) -gt $StartDate -and (Get-Date($_.TimeCreated)) -lt $EndDate}; | |
if ($ThisLog) | |
{ | |
$FileName = "$($PWD.Path)\$(($Log.LogName).Replace('/','-')).csv"; | |
Write-Output "Exporting : $($FileName)"; | |
$ThisLog |Export-Csv -Path $FileName -NoTypeInformation; | |
} | |
} | |
} | |
catch | |
{ | |
throw $_; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment