2014-05-22 28 views
0

我試圖在Windows 2k8中使用powershell尾日誌文件,然後讓它發送到Windows事件查看器。PowerShell:拖尾日誌文件,並將結果發送到Windows系統事件日誌

我知道的PowerShell可以「尾巴」的日誌運行:

Get-Content -Path C:\logs\events.log -Wait 

這將尾實時日誌(類似於在linux尾巴-F)。

PowerShell還可以寫入到Windows事件系統日誌:

Write-EventLog System -source System -eventid 12345 -message "test" 

我不知道如何(如果)我能管的尾日誌結果作爲寫事件日誌消息?

我在想,既然這是一個Windows環境,它可能需要腳本來調用Get-Content中的消息變量?有誰知道如何,或者如果這可以完成?我的谷歌搜索沒有讓我去實時Windows事件日誌記錄。

回答

3

你或許可以做這樣的事情:

function Write-EventlogCustom($msg) { 
    Write-EventLog System -source System -eventid 12345 -message $msg 
} 

Get-Content -Path C:\logs\events.log -Wait | % {Write-EventlogCustom $_} 

你不一定需要做一個功能,我只是用它來使代碼更乾淨。

+0

謝謝。我並不是100%熟悉PowerShell的語法,非常感謝! – hobbes