Logging

將 Windows 系統日誌事件擷取到文本文件中

  • June 3, 2020

為了滿足愚蠢的合規性要求,我需要將 w32time 事件擷取到文本文件中。在 Windows 中有沒有辦法做到這一點?

快速回答; 手動,從事件查看器中,點擊系統日誌,然後轉到查看 > 過濾器並W32Time從事件源下拉列表中進行選擇。按確定。然後轉到操作 > 導出列表並輸入您的文件名。如果您還需要詳細資訊,則必須使用操作 > 將日誌文件另存為保存整個日誌文件,然後從保存類型下拉列表中選擇Tab Delimeted或。Comma Separated

長答案是,腳本。使用 WMI 查詢Win32_NTLogEvent並使用 FileSystemObject 或輸出重定向將其假離線到文件:

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NTLogEvent WHERE SourceName = 'W32Time'",,48)

Dim fso : Set fso = CreateObject("scripting.filesystemobject")
Dim ts : Set ts = fso.CreateTextFile("X:\w32time_events.txt", True)

For Each objItem in colItems
   ts.WriteLine "Category: " & objItem.Category
   ts.WriteLine "CategoryString: " & objItem.CategoryString
   ts.WriteLine "ComputerName: " & objItem.ComputerName
   ts.WriteLine "Data: " & objItem.Data
   ts.WriteLine "EventCode: " & objItem.EventCode
   ts.WriteLine "EventIdentifier: " & objItem.EventIdentifier
   ts.WriteLine "EventType: " & objItem.EventType
   ts.WriteLine "InsertionStrings: " & objItem.InsertionStrings
   ts.WriteLine "Logfile: " & objItem.Logfile
   ts.WriteLine "Message: " & objItem.Message
   ts.WriteLine "RecordNumber: " & objItem.RecordNumber
   ts.WriteLine "SourceName: " & objItem.SourceName
   ts.WriteLine "TimeGenerated: " & objItem.TimeGenerated
   ts.WriteLine "TimeWritten: " & objItem.TimeWritten
   ts.WriteLine "Type: " & objItem.Type
   ts.WriteLine "User: " & objItem.User
   ts.WriteBlankLines 1
Next

ts.Close

Set ts = Nothing
Set fso = Nothing
Set colItems = Nothing
Set objWMIService = Nothing

作弊選項,如果您不介意的話;在cmd命令提示符下,嘗試:

wmic NTEVENT | find /i "W32Time" > W32Time_Events.txt

高溫高壓

J。

引用自:https://serverfault.com/questions/295224