使用以下内容:
$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
没有全文?
我需要在代码中更改哪些内容才能为这些列添加更多文本?
答案 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中打开表格。
答案 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