79446935

Date: 2025-02-18 01:35:08
Score: 0.5
Natty:
Report link

Here is a working code based on @MagTuns answer regarding separate files for each logname

Added

Code

$Begin = '18/02/2025 00:00:00'
$End = '18/02/2025 00:59:59'
$path = "C:\temp\logevent\"
If(!(test-path $path))
{
    New-Item -ItemType Directory -Force -Path $path
}
$allLog = (Get-WinEvent -ListLog * -ErrorAction SilentlyContinue).LogName
foreach ($lognameName in $allLog){
    Write-Host "Processing $lognameName..."
    $lognameFile = $lognameName.Replace("/", "-")
    $datetimenow =  [DateTime]::Now.ToString("yyyy_MM_dd HH_mm_ss")
    Get-WinEvent -FilterHashtable @{logname = $lognameName; StartTime = "$Begin"; EndTime = "$End";Level=1,2,3; } -ErrorAction SilentlyContinue | Select-Object * | Out-File -Enc UTF8 -FilePath "$path$datetimenow_winevent_$lognameFile.txt"
}
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @MagTuns
  • Low reputation (1):
Posted by: Jan S. Christensen