При диагностике проблем на Windows может возникнуть необходимость проанализировать сразу несколько файлов журналов событий. Разобраться с ними по одному может занять много времени. В этой статье мы расскажем, как объединить все журналы Windows в один файл, чтобы облегчить поиск нужной информации.
Почему объединение журналов Windows полезно?
Каждый файл журнала (.evtx) содержит сведения о событиях в системе. Объединив их, можно получить полную картину работы системы и быстрее выявить причину сбоев или нестабильной работы.
Шаги по объединению журналов Windows в один файл
Ниже приведен полезный скрипт, который автоматизирует процесс объединения всех файлов .evtx в одной папке в единый файл журнала. Это значительно упростит диагностику и сэкономит время.
Как использовать скрипт?
- Скопируйте папку с журналами (
C:\windows\system32\winevt\Logs) - Скачайте скрипт с GitHub по ссылке.
- Запустите скрипт и укажите путь до папки (ключ -FolderPath) с журналами evtx, куда они были ранее скопированы, чтобы объединить все журналы в один файл. Можно также предварительно перейти в эту папку, и запустить скрипт без ключа.
В итоге, по завершении работы скрипта в папке с журналами появится файл merge.evtx.
Текст скрипта для объединения журналов
Вот текст скрипта на случай, если вам нужно сохранить его на будущее:
#Original code here : https://github.com/abhinav-eyesOnglass/evtx/tree/master
# MergeEventsInside.ps1
#
# - v2 : Fixed Installer bug (setting wrong registry keys in v1)
# : Add the possibility to run the script manually or just double click on it
#
# - v3 : Fixed a bug in FolderPath management to handle path with special characters such ad '[' & ']'
# Using -LiteralPath instead of -Path and Out-File instead of Add-Content
#
param(
[string]$FolderPath
)
# Check if an argument is provided
# If no argument: Look for evtx files in the current folder, supposing it's been started manually
if (!$FolderPath)
{
$FolderPath = Split-Path ((Get-Variable MyInvocation).Value).MyCommand.Path
}
write-host $FolderPath -ForegroundColor Cyan
# Check the argument is a folder
if ((Test-Path -LiteralPath $FolderPath -PathType Container)-eq $false) {
$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("This folder doesn't exist!",0,$FolderPath,0x1)
}
else
{
$ListOfEvtxFiles = (Get-ChildItem -LiteralPath $FolderPath -File -Filter *.evtx | ? { $_.Name -ne "Merge.evtx" }).FullName
# Check if the folder contains .evtx files
if ($ListOfEvtxFiles.count -eq 0)
{
$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("Invalid path: Doesn't contain any evtx files!",0,$FolderPath,0x1)
}
else
{
# Informing the user
Write-Host "Merge the event files found in the `"$FolderPath`" folder ..."
# Generate the XML File for the merge operation
$Filter = "*"
$StructuredQueryFilePath = $FolderPath+"\StructuredQuery.xml"
$StructuredQueryXMLFile = New-Item -Path $StructuredQueryFilePath -ItemType File -Force
$String = "<QueryList>`n"
$String += " <Query Id=`"0`" Path=`"file://"+$ListOfEvtxFiles[0]+"`">`n"
$ListOfEvtxFiles | % {
$String += " <Select Path=`"file://$_`">"+$Filter+"</Select>`n"
}
$String += " </Query>`n"
$String += "</QueryList>`n"
$string | Out-File -LiteralPath $StructuredQueryXMLFile
# Generate the merge operation
wevtutil /sq epl $StructuredQueryXMLFile "$FolderPath\Merge.evtx" /ow:true
Write-Host "All the events are merged into the $FolderPath\Merge.evtx file"
$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("Done in $FolderPath\Merge.evtx",0,"Merge operation",0x1)
}
}
Преимущества использования скрипта
- Ускоряет диагностику – больше не нужно копаться в каждом файле отдельно.
- Удобство анализа – все события собраны в одном месте.
