Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A script that will pull the logs from Windows that have records, between the dates specified.
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
You can’t perform that action at this time.