Script for automating the backup of Windows Server event logs.

PHOTO EMBED

Fri Jan 27 2023 04:46:32 GMT+0000 (Coordinated Universal Time)

Saved by @thefunkytechguy #powershell #activedirectory

$eventlogs = "Application", "Security", "System"
$lognames = $eventlogs | ForEach-Object {$_ + ".evtx"}
$path = "C:\EventLogs\"
$date = (Get-Date).AddDays(-30)

foreach ($logname in $lognames) {
    $log = Get-WinEvent -LogName $logname -FilterXPath "*[System[TimeCreated[@SystemTime>='$date']]]"
    $log | Export-EventLog -Path "$path$logname"
}
content_copyCOPY