2016-04-13 78 views
-1

wevtutilコマンドを使用して、Windowsサーバのイベントログをテキストファイルにインポート/読み込みしようとしていますか。wevtutilクエリを1行に出力する

$ wevtutil qe Application \rd:true \f:text(アプリケーションログを読み取り) を、私のコマンドの出力例を、次のとおりです:私はfile.txtに私のログを書き込むには、次のコマンドを使用し

Event[1]: 
    Log Name: Application 
    Source: Microsoft-Windows-Security-SPP 
    Date: 2016-03-29T13:02:27.000 
    Event ID: 8196 
    Task: N/A 
    Level: Information 
    Opcode: N/A 
    Keyword: Classic 
    User: N/A 
    User Name: N/A 
    Computer: WIN-IONOGQTF9O5 
    Description: License Activation Scheduler (sppuinotify.dll) 

Event[2]: 
    Log Name: Application 
    Source: Microsoft-Windows 
    Date: 2016-06-29T13:02:57.000 
    Event ID: 3444 
    Task: N/A 
    Level: Critical 
    Opcode: N/A 
    Keyword: Classic 
    User: N/A 
    User Name: N/A 
    Computer: WIN-IONOGDFFF9O5 
    Description: AIRO.Activation code(sppuinotify.dll) 

(実際には、2つのサンプルログ)。 しかし、上記の単一行の複数行出力ではなく、.txtファイルに1行としてログを書きたいと思っています。 wevtutil commandユーティリティは以下のように、単一の行にログを書き込むことがあります:

Event[1]:Log Name: Application Source: Microsoft-Windows-Security-SPP Date: 2016-03-29T13:02:27.000 Event ID: 8196 Task: N/A Level: Information Opcode: N/A Keyword: Classic User: N/A User Name: N/A Computer: WIN-IONOGQTF9O5 Description: License Activation Scheduler (sppuinotify.dll) 
Event[2]:Log Name: Application Source: Microsoft-Windows Date: 2016-03-29T13:02:27.000 Event ID: 8196 Task: N/A Level: Information Opcode: N/A Keyword: Classic User: N/A User Name: N/A Computer: WIN-IONOGQTF9O5 Description: License Activation Scheduler (sppuinotify.dll) 

ありがとう!

+0

Get-Wineventを使用する必要がある場合欲しいのは – Paul

+0

@Paul:返事はありがとうございます。しかし、get_eventlogとwevtutilの出力は全く異なります! –

+0

get-eventlogが出力するイベントには、wevtutilのサンプル出力に含まれるすべての情報が含まれています。データをまとめてファイルに保存するだけです – Paul

答えて

0
$logname = "Application"  
$events = Get-EventLog -LogName $logname 

$arr = @() 
$counter = 1 

foreach($event in $events){ 
$arr += "Event[$counter]:Log Name: $logname Source: $($event.Source) Date: $($event.TimeWritten) Event ID: $($event.EventID) Task: $($event.Category) Level: $($event.EntryType) ..." 
$counter++ 
} 

$arr | out-file events.txt 

あなたはオペコード、キーワードなどがあなたの代わりにユーティリティの `取得-eventlog`のような組み込みコマンドを使用する場合は、しかし、あなたの出力をフォーマットすることができます代わりにGet-Eventlog

関連する問題