
일반적으로 오류 1000이 발생하는 일부 서버가 있습니다. 항상 같은 애플리케이션인지, 아니면 다른 애플리케이션인지 확인하고 싶습니다. 나는 이것을 사용하고 있습니다 :
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]}
이렇게 하면 내가 원하는 출력을 얻을 수 있습니다. 단, 출력은 세 줄에 걸쳐 생성되며, 내보내기-CSV는 이를 제대로 구문 분석하지 않습니다. 한 줄에 모두 표시하려면 어떻게 해야 합니까?
답변1
모든 이벤트 유형에 대해 정확하지는 않을 수도 있지만 속성은 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