에 로그 맞춤 로그 리더를 작성. 데이터는 이렇게 보입니다 :내가 로그 리더의 생성을 시도하고 PowerShell을
2017-11-27 13 : 24 : 41,791 [8] 정보 CTSipEndpoint.CLogger.provider.gsiplib [(null)] - -00001 [정보] 정보 | 4744 | 등록 대화 상자 [1] 2-e : 5; t : 1-3 (dn : 85188)
2017-11-27 13 : 24 : 41,791 INFO CTSipEndpoint.CLogger.provider.gsiplib [(null)] - -00001 [정보] 정보 | 4744 | 지난 48 시간
- 반환에만 라인은 더 쿼리 : REGISTERdialog [1] 이벤트 2 REG/I는 다음을 수행하려고
을 받아 들였다. 다음과 같은 문구가 포함 된 모든 행 반환 이상에서
- : "오류" "장치", "스피커를 식별 할 수 없습니다!", "존재하지 않는"지금까지 나는 단지이
을 "경고" 비효율적 인 방식으로 작동하도록 만들었습니다. 각 구문에 대해 파일에 대해 실행되고 배열이 추가됩니다. 불행히도 이는 날짜 시간이 비 순차적이라는 것을 의미합니다. 이제 스크립트의 끝에서 콘텐츠 개체를 순서대로 정렬하거나이 쿼리를 더 똑똑하게 실행하는 방법을 찾아야합니다. 여기 참조를 위해 내 스크립트입니다 필요가 조정하는 경우 여기
$logfile = "C:\users\test\desktop\programlogs.log"
$content = ""
cat $logfile |
Select-String "ERROR" -SimpleMatch |
select -expand line |
foreach {
$_ -match '(.+)\s\[(ERROR)\]\s(.+)'| Out-Null
$error_time = [datetime]($matches[1]).split(",")[0]
if ($error_time -gt (Get-Date).AddDays(-2)) {
$content += $_ + "`n"
}
}
cat $logfile |
Select-String "device" -SimpleMatch |
select -expand line |
foreach {
$_ -match '(.+)\s\[(device)\]\s(.+)'| Out-Null
$error_time = [datetime]($matches[1]).split(",")[0]
if ($error_time -gt (Get-Date).AddDays(-2)) {
$content += $_ + "`n"
}
}
cat $logfile |
Select-String "does not exist" -SimpleMatch |
select -expand line |
foreach {
$_ -match '(.+)\s\[(does not exist)\]\s(.+)'| Out-Null
$error_time = [datetime]($matches[1]).split(",")[0]
if ($error_time -gt (Get-Date).AddDays(-2)) {
$content += $_ + "`n"
}
}
cat $logfile |
Select-String "Could not identify speaker!" -SimpleMatch |
select -expand line |
foreach {
$_ -match '(.+)\s\[(Could not identify speaker!)\]\s(.+)'| Out-Null
$error_time = [datetime]($matches[1]).split(",")[0]
if ($error_time -gt (Get-Date).AddDays(-2)) {
$content += $_ + "`n"
}
}
cat $logfile |
Select-String "Warn" -SimpleMatch |
select -expand line |
foreach {
$_ -match '(.+)\s\[(Warn)\]\s(.+)'| Out-Null
$error_time = [datetime]($matches[1]).split(",")[0]
if ($error_time -gt (Get-Date).AddDays(-2)) {
$content += $_ + "`n"
}
}
$content = $content | select -uniq
$file = "c:\temp\shortenedlog.txt"
$content| Add-Content -Path $file
안녕, 불행하게도 난 그냥 위의 코드와 에러 코드를 얻을 : 예외 호출 "하위 문자열" "이"인수 (들) :. "길이가 제로보다 작은 매개 변수 이름이 될 수 없습니다 : 길이 "C에서 : 사용자 \ \ 사용자 이름 \ 바탕 화면 \ LogReader.ps1 : 5 문자 : 5 + $ 날짜 = 날짜 $의 line.substring (0, $의 line.indexof (", ")) + ~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified (:) [] MethodInvocationException + FullyQualifiedErrorId : ArgumentOutOfRangeException –
죄송합니다. 로그에 빈 줄이 있어야합니다. 스크립트를 업데이트했습니다. –
도움 주셔서 감사합니다. 파일이 방대하고 반복 할 때 너무 오랜 시간이 걸렸기 때문에 단순한 해결책을 찾지 못했습니다. –