概要
Windows PCの不具合を調査する方法の1つにログがあります。
Windows イベント ビューアーで閲覧が可能なログです。しかし、公式ツールでは、調査する時に速度が遅かったり、フィルタリングが扱いづらい為、Excelで加工する時の説明です。さらに、仕様の問題でイベント ビューアー機能だけでは複雑なクエリのエクスポートもしづらいです。私は別の手段としてExcelで閲覧できるように加工しています。今回はその手順を書き留めました。
目的
Windowsの物理故障やOS、ソフトウェア上の不具合原因を調査すること
PC利用者の利用側のミスなどを特定すること
故障以外にも正常な動作だが、意図しない設定などが原因の場合があります。それらの正常なログも閲覧できるように調査可能にする。
想定読者
ITスペシャリスト、Windowsのログを閲覧し調査出来る、PowershellなどWindowsのコマンドを理解している
大まかな作業フロー
手順1
ここで作るスクリプトでは、次のログをエクスポートするように書いています。
日常で使いやすいように、フォルダの作成もスクリプトで実行しています。フォルダは、スクリプトを実行したPCのコンピュータ名と実行日付です。
スクリプトが長いので折りたたんであります。クエリはイベント ビューアーのカスタムビューのXMLから流用しています。多少スクリプト実行させる都合で書き換えた程度でソースもそのままです。そのため、一部クエリ結果はエラーがでることもあります。エラー確認しやすいように実行時の結果はTerminalへ表示されるようにしました。
@echo off
REM Get Computer Name
set hostname=%COMPUTERNAME%
REM Get Execution Date
for /f " tokens=2 delims==." %%G in ('wmic OS Get localdatetime /value') do set "datetime=%%G"
set "date=%datetime:~0,8%"
REM Variable to create a folder name on the desktop that combines the computer name and date.
set "dirname=%HOMEDRIVE%%HOMEPATH%\Desktop\%hostname%_%date%"
REM Create a folder on the desktop with the variable PATH
echo A folder is created on the desktop. The folder name is ComputerName_yyyymmdd
mkdir "%dirname%"
echo Logs from the last 30 days are exported. Please wait until it completes...
@echo on
wevtutil epl Application "%dirname%\Application.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Security "%dirname%\Security.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl System "%dirname%\System.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Internet Explorer "%dirname%\Internet Explorer.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-AppV-Client/Admin "%dirname%\Microsoft-AppV-Client_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-AppV-Client/Virtual Applications "%dirname%\Microsoft-AppV-Client_Virtual Applications.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-All-User-Install-Agent/Admin "%dirname%\Microsoft-Windows-All-User-Install-Agent_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-AppHost/Admin "%dirname%\Microsoft-Windows-AppHost_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-Application Server-Applications/Admin "%dirname%\Microsoft-Windows-Application Server-Applications_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-AppModel-Runtime/Admin "%dirname%\Microsoft-Windows-AppModel-Runtime_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-AppReadiness/Admin "%dirname%\Microsoft-Windows-AppReadiness_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-AssignedAccess/Admin "%dirname%\Microsoft-Windows-AssignedAccess_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-AssignedAccessBroker/Admin "%dirname%\Microsoft-Windows-AssignedAccessBroker_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-Storage-ATAPort/Admin "%dirname%\Microsoft-Windows-Storage-ATAPort_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-BitLocker-DrivePreparationTool/Admin "%dirname%\Microsoft-Windows-BitLocker-DrivePreparationTool_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Client-Licensing-Platform/Admin "%dirname%\Microsoft-Client-Licensing-Platform_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-DataIntegrityScan/Admin "%dirname%\Microsoft-Windows-DataIntegrityScan_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-DataIntegrityScan/CrashRecovery "%dirname%\Microsoft-Windows-DataIntegrityScan_CrashRecovery.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-DSC/Admin "%dirname%\Microsoft-Windows-DSC_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-DeviceManagement-Enterprise-Diagnostics-Provider/Admin "%dirname%\Microsoft-Windows-DeviceManagement-Enterprise-Diagnostics-Provider_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-DeviceManagement-Enterprise-Diagnostics-Provider/Autopilot "%dirname%\Microsoft-Windows-DeviceManagement-Enterprise-Diagnostics-Provider_Autopilot.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-DeviceSetupManager/Admin "%dirname%\Microsoft-Windows-DeviceSetupManager_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-Dhcp-Client/Admin "%dirname%\Microsoft-Windows-Dhcp-Client_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-Dhcpv6-Client/Admin "%dirname%\Microsoft-Windows-Dhcpv6-Client_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-Diagnosis-Scripted/Admin "%dirname%\Microsoft-Windows-Diagnosis-Scripted_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-Storage-Disk/Admin "%dirname%\Microsoft-Windows-Storage-Disk_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-DxgKrnl-Admin "%dirname%\Microsoft-Windows-DxgKrnl-Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-EDP-Application-Learning/Admin "%dirname%\Microsoft-Windows-EDP-Application-Learning_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-EDP-Audit-Regular/Admin "%dirname%\Microsoft-Windows-EDP-Audit-Regular_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-EDP-Audit-TCB/Admin "%dirname%\Microsoft-Windows-EDP-Audit-TCB_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Client-License-Flexible-Platform/Admin "%dirname%\Microsoft-Client-License-Flexible-Platform_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-GenericRoaming/Admin "%dirname%\Microsoft-Windows-GenericRoaming_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-Hyper-V-Guest-Drivers/Admin "%dirname%\Microsoft-Windows-Hyper-V-Guest-Drivers_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-Hyper-V-Hypervisor-Admin "%dirname%\Microsoft-Windows-Hyper-V-Hypervisor-Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-Hyper-V-VID-Admin "%dirname%\Microsoft-Windows-Hyper-V-VID-Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-Kernel-EventTracing/Admin "%dirname%\Microsoft-Windows-Kernel-EventTracing_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-KeyboardFilter/Admin "%dirname%\Microsoft-Windows-KeyboardFilter_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-ModernDeployment-Diagnostics-Provider/Autopilot "%dirname%\Microsoft-Windows-ModernDeployment-Diagnostics-Provider_Autopilot.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-ModernDeployment-Diagnostics-Provider/ManagementService "%dirname%\Microsoft-Windows-ModernDeployment-Diagnostics-Provider_ManagementService.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-ModernDeployment-Diagnostics-Provider/Admin "%dirname%\Microsoft-Windows-ModernDeployment-Diagnostics-Provider_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-ModernDeployment-Diagnostics-Provider/Diagnostics "%dirname%\Microsoft-Windows-ModernDeployment-Diagnostics-Provider_Diagnostics.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-MUI/Admin "%dirname%\Microsoft-Windows-MUI_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-PowerShell/Admin "%dirname%\Microsoft-Windows-PowerShell_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-PrintBRM/Admin "%dirname%\Microsoft-Windows-PrintBRM_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-PrintService/Admin "%dirname%\Microsoft-Windows-PrintService_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-Provisioning-Diagnostics-Provider/Admin "%dirname%\Microsoft-Windows-Provisioning-Diagnostics-Provider_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-Provisioning-Diagnostics-Provider/AutoPilot "%dirname%\Microsoft-Windows-Provisioning-Diagnostics-Provider_AutoPilot.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-Provisioning-Diagnostics-Provider/ManagementService "%dirname%\Microsoft-Windows-Provisioning-Diagnostics-Provider_ManagementService.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-PushNotification-Platform/Admin "%dirname%\Microsoft-Windows-PushNotification-Platform_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-RemoteApp and Desktop Connections/Admin "%dirname%\Microsoft-Windows-RemoteApp and Desktop Connections_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-RemoteAssistance/Admin "%dirname%\Microsoft-Windows-RemoteAssistance_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-RemoteDesktopServices-RdpCoreTS/Admin "%dirname%\Microsoft-Windows-RemoteDesktopServices-RdpCoreTS_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-RetailDemo/Admin "%dirname%\Microsoft-Windows-RetailDemo_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-SecurityMitigationsBroker/Admin "%dirname%\Microsoft-Windows-SecurityMitigationsBroker_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-SmartCard-TPM-VCard-Module/Admin "%dirname%\Microsoft-Windows-SmartCard-TPM-VCard-Module_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-SMBDirect/Admin "%dirname%\Microsoft-Windows-SMBDirect_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-SMBWitnessClient/Admin "%dirname%\Microsoft-Windows-SMBWitnessClient_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-Storage-Tiering/Admin "%dirname%\Microsoft-Windows-Storage-Tiering_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-Storage-ClassPnP/Admin "%dirname%\Microsoft-Windows-Storage-ClassPnP_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-Storage-Storport/Admin "%dirname%\Microsoft-Windows-Storage-Storport_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-TerminalServices-ClientUSBDevices/Admin "%dirname%\Microsoft-Windows-TerminalServices-ClientUSBDevices_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-TerminalServices-LocalSessionManager/Admin "%dirname%\Microsoft-Windows-TerminalServices-LocalSessionManager_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-TerminalServices-PnPDevices/Admin "%dirname%\Microsoft-Windows-TerminalServices-PnPDevices_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-TerminalServices-Printers/Admin "%dirname%\Microsoft-Windows-TerminalServices-Printers_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-TerminalServices-RemoteConnectionManager/Admin "%dirname%\Microsoft-Windows-TerminalServices-RemoteConnectionManager_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-TerminalServices-ServerUSBDevices/Admin "%dirname%\Microsoft-Windows-TerminalServices-ServerUSBDevices_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-Troubleshooting-Recommended/Admin "%dirname%\Microsoft-Windows-Troubleshooting-Recommended_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-User Device Registration/Admin "%dirname%\Microsoft-Windows-User Device Registration_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-VerifyHardwareSecurity/Admin "%dirname%\Microsoft-Windows-VerifyHardwareSecurity_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-WindowsBackup/ActionCenter "%dirname%\Microsoft-Windows-WindowsBackup_ActionCenter.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Microsoft-Windows-Workplace Join/Admin "%dirname%\Microsoft-Windows-Workplace Join_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl OpenSSH/Admin "%dirname%\OpenSSH_Admin.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Windows PowerShell "%dirname%\Windows PowerShell.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl Key Management Service "%dirname%\Key Management Service.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
wevtutil epl HardwareEvents "%dirname%\HardwareEvents.evtx" /q:"*[System[(Level=1 or Level=2 or Level=3 or Level=4 or Level=0) and TimeCreated[timediff(@SystemTime) <= 2592000000]]]"
echo Export is complete. Please check your desktop.
pause
手順2
このスクリプトは手順1で作成されたフォルダに保存して実行するように書いています。Set-LocationでスクリプトのカレントPathを取得してそのあとのPathの入力を省略した。フォルダ内のイベントログファイルすべてを一つのタブ区切りテキストとして作成します。
下記のスクリプトをps1ファイルで保存して使っています。
echo "Check to see if the Ps1 file can run the OS settings."
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
Set-Location -Path $PSScriptRoot
echo "Joining Evtx files in folder and creating TSV file..."
echo "Please wait..."
Get-WinEvent -Path '*.evtx' | Select-Object TimeCreated, LevelDisplayName, Level,ID,ProviderName,Message | Foreach-Object { "$($_.TimeCreated)`t$($_.LevelDisplayName)`t$($_.Level)`t$($_.ID)`t$($_.ProviderName)`t$($_.Message)"} | Out-File -Encoding utf8 -FilePath 'EventLog.tsv'
echo "Done"
Read-Host -Prompt "Press Enter to exit"
手順3
最後はスクリプトにはせず、テキストエディタでの文字置換作業です。
イベント ビューアーのDescription、Message項目は複数行の情報になる場合、TSV上でも複数行になってしまいます。この状態を避けたい為、今回のエクスポート情報の特徴から、行頭がmm/dd/yyyyではない時、前の行の改行コードを削除するように処理します。検索文字列では正規表現を使っています。
手順4
Excelでテキストをインポートします。区切りはタブを選択して取り込み、作業完了です。
ログによっては、Message項目が複数セルに分かれる場合は手順2で各フィールドへタブを追加する部分などの文字の加工処理を調整して使うとExcel上で作業を減らせると思います。