Skip to content

Instantly share code, notes, and snippets.

@jeffpatton1971
Created August 17, 2017 20:51
Show Gist options
  • Save jeffpatton1971/f7875a6317e0c3ae4d905a4ab9d74396 to your computer and use it in GitHub Desktop.
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.
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