事件查看器日志问题

时间:2014-01-29 14:31:42

标签: powershell powershell-v2.0 event-viewer

使用以下内容:

$pattern = 'Unable to create Load Balance Manager object!'
$events = Get-WinEvent -ea SilentlyContinue `
-ProviderName "Hyperion Financial Data Quality Management - Task Manager Service"|
Where-Object { $_.TimeCreated -gt [datetime]::now.AddMinutes(-15) -and $_.Message -match $pattern }
$events   >> G:\Sysadmin\FDMmonitor\Error.txt  

我收到Error.txt如下:

TimeCreated         ProviderName                         Id Message            
-----------         ------------                         -- -------            
1/24/2014 11:41:... Hyperion Financi...                   0 Unable to create...
1/24/2014 11:41:... Hyperion Financi...                   0 Unable to create...
1/24/2014 11:41:... Hyperion Financi...                   0 Unable to create...
1/24/2014 11:40:... Hyperion Financi...                   0 Unable to create...
1/24/2014 11:39:... Hyperion Financi...                   0 Unable to create...
1/24/2014 11:39:... Hyperion Financi...                   0 Unable to create...
1/24/2014 11:39:... Hyperion Financi...                   0 Unable to create...
1/24/2014 11:39:... Hyperion Financi...                   0 Unable to create...
1/24/2014 11:38:... Hyperion Financi...                   0 Unable to create...
1/24/2014 11:37:... Hyperion Financi...                   0 Unable to create...
1/24/2014 11:37:... Hyperion Financi...                   0 Unable to create...
1/24/2014 11:37:... Hyperion Financi...                   0 Unable to create...
1/24/2014 11:36:... Hyperion Financi...                   0 Unable to create...
1/24/2014 11:36:... Hyperion Financi...                   0 Unable to create...

我没有收到,为什么TimeCreated, ProviderName and Message没有全文?

我需要在代码中更改哪些内容才能为这些列添加更多文本?

6 个答案:

答案 0 :(得分:3)

难道你不在美国吗?我问,因为我在英国,我发现Get-WinEvent日志可以从这个添加或序言中受益:

[System.Threading.Thread]::CurrentThread.CurrentCulture = `
New-Object "System.Globalization.CultureInfo" "en-US"

答案 1 :(得分:3)

如果您希望在屏幕上看到结果而不缩短任何内容,可以尝试更改代码:

 $events = Get-WinEvent -ea SilentlyContinue `
-ProviderName "Hyperion Financial Data Quality Management - Task Manager Service"|
Where-Object { $_.TimeCreated -gt [datetime]::now.AddMinutes(-15) -and $_.Message -match $pattern }
$events |format-table -AutoSize |out-file -append -encoding Ascii G:\Sysadmin\FDMmonitor\Error.txt -width 300

答案 2 :(得分:2)

您可以使用export-csv类。 这样您就可以在Excel中打开表格。

http://technet.microsoft.com/en-us/library/ee176825.aspx

答案 3 :(得分:2)

尝试使用-ExpandProperty选项。见this Technet link

答案 4 :(得分:2)

不要使用追加运算符,请尝试:

... | Out-File G:\Sysadmin\FDMmonitor\Error.txt -Width 200

您可以使用-Width参数使输出宽度尽可能宽。

答案 5 :(得分:1)

有时它仍会发送省略号,即使你在管道中有一个巨大的out-file -width。在这些情况下,您可以将Format-Table-Wrap-AutoSize参数一起使用,以防止在输出之前截断。

Format-Table -Wrap -AutoSize