2

使用如下:

$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不提供全文?

我需要在代码中进行哪些更改才能为这些列获取更多文本?

4

6 回答 6

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
于 2014-01-29T16:35:41.260 回答
3

会不会是你不在美国?我问是因为我在英国,我发现 Get-WinEvent 日志受益于这个添加或序言:

[System.Threading.Thread]::CurrentThread.CurrentCulture = `
New-Object "System.Globalization.CultureInfo" "en-US"
于 2014-01-29T15:49:39.767 回答
2

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

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

于 2014-01-29T14:47:54.057 回答
2

试试这个-ExpandProperty选项。请参阅此 Technet 链接

于 2014-01-29T18:35:09.227 回答
2

而不是使用附加运算符,试试这个:

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

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

于 2014-01-29T21:36:26.923 回答
1

有时它仍然会发送省略号,即使您还有大量out-file -width的管道。在这些情况下,您可以使用Format-Tablewith-Wrap-AutoSize参数来防止在输出之前截断。

Format-Table -Wrap -AutoSize
于 2014-01-30T05:47:14.313 回答