我有一些服务器通常有错误1000s。 我想要查找它是否一直是同一个应用程序,或者它是不同的应用程序。 我正在使用这个:
Get-EventLog application 1000 -entrytype error -newest 10 | select timegenerated,message | Export-Csv errors.csv
并且输出显示应用程序名称(特别是exe文件)作为多行消息字段的一部分。
我一直无法弄清楚如何从输出中提取应用程序名称。
输出到Get-Member使得它看起来像消息字段是一个数组,但我不知道如何提取该部分的数组在这一点上。
Get-EventLog application 1000 -entrytype error -newest 10 | %{$_.machinename,$_.timegenerated,$_.ReplacementStrings[0]}
这给了我想要的输出,除了它是通过三行生成的,Export-CSV不想正确parsing它。 我怎样才能把他们全部在一行?
对于所有的事件types,这可能不是准确的,但是属性ReplacementStrings是一个数组,其中第一个元素是查看InstanceID 1000时的可执行文件的名称:
> Get-EventLog application 1000 -entrytype error -newest 10 | %{$_.ReplacementStrings[0]} Ssms.exe Ssms.exe Ssms.exe uniStudio.exe SwyxIt!.exe Ssms.exe uniRTE.exe uniStudio.exe Ssms.exe Ssms.exe
我的PS-foo在上午的这个时候很弱,但是我确定有一种方法可以将它与你的select命令结合起来,并将它们导出到你的CSV文件中。
根据你的更新; 这将以表格格式获得所需的输出。 我不知道它将如何与export-csv玩,虽然:
Get-EventLog application 1000 -entrytype error -newest 10|Format-Table @{Expression={$_.machinename};Label="Machine Name";width=25},@{Expression={$_.timegenerated.DateTime};Label="DateTime";width=25},@{Expression={$_.ReplacementStrings[0]};Label="EXEName";width=25}
没关系; 我上次更新的方式太复杂了。 这应该工作得很好(我知道今天晚些时候我会更好):
> Get-EventLog application 1000 -entrytype error -newest 10|Select-Object timegenerated,message,@{name='Executable';expression={$_.ReplacementStrings[0]}}|Export-CSV errors.csv TimeGenerated Message Executable ------------- ------- ---------- 14/01/2014 7:23:13 AM Faulting application name: Ssms.exe,... Ssms.exe 13/01/2014 7:26:44 AM Faulting application name: Ssms.exe,... Ssms.exe 10/01/2014 7:30:24 AM Faulting application name: Ssms.exe,... Ssms.exe 8/01/2014 5:25:13 PM The description for Event ID '1000' ... uniStudio.exe 31/12/2013 3:09:58 PM The description for Event ID '1000' ... SwyxIt!.exe 19/12/2013 7:35:21 AM Faulting application name: Ssms.exe,... Ssms.exe 18/12/2013 2:55:45 PM Faulting application name: uniRTE.ex... uniRTE.exe 18/12/2013 9:25:49 AM The description for Event ID '1000' ... uniStudio.exe 18/12/2013 7:32:29 AM Faulting application name: Ssms.exe,... Ssms.exe 16/12/2013 1:22:38 PM Faulting application name: Ssms.exe,... Ssms.exe