【问题标题】:Issue with Eventviewer log事件查看器日志问题
【发布时间】:2014-02-21 10:23:00
【问题描述】:

在下面使用:

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

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

【问题讨论】:

    标签: powershell powershell-2.0 event-viewer


    【解决方案1】:

    如果你想得到你在屏幕上看到的结果而不做任何缩短,你可以尝试像这样改变你的代码:

     $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
    

    【讨论】:

    • 要提炼这一点,这个答案的重要部分是:在将输出传输到文件之前先通过| Format-Table -AutoSize 进行管道传输。但是请注意,如果数据太长,不适合的列将从末尾删除。另外注意| Out-File -Append>>是一样的(后者是前者的简写)
    • 正确,这就是为什么我通过限定它来开始我的回答。我不会使用 OP 要求的输出格式,但这是一个选择,而不是问题。
    【解决方案2】:

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

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

    【讨论】:

    • 感谢您的信息..!:)
    【解决方案3】:

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

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

    【讨论】:

      【解决方案4】:

      试试-ExpandProperty 选项。见this Technet link

      【讨论】:

        【解决方案5】:

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

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

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

        【讨论】:

          【解决方案6】:

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

          Format-Table -Wrap -AutoSize
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2017-04-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2023-02-20
            • 2019-05-16
            相关资源
            最近更新 更多