VDI 환경의 로그온 모니터링 제품에서 PowerShell의 로그를 구문 분석하려고합니다. 이 로그 파일을 기록하며이 줄을 쓴다 :로그 파일에서 값 추출
2016-12-15T14:15:02.863 INFO (0908-0bd8) [LogonMonitor::LogSummary] Logon Time: 4.03 seconds
내가 뭘하려고 오전 그냥 "4.03"문자열에서 구문 분석과 값의 배열에 저장입니다. 다음을 수행하여 로그 파일에서 전체 문자열을 선택할 수 있습니다.
$LogPath = "\\file-svr\Logs\"
$strings = Select-String -path $LogPath\*.txt -pattern "[LogonMonitor::LogSummary] Logon Time:" -AllMatches -simplematch
foreach ($string in $strings) {
$found = $string -match '\d\.'
if ($found) {
$time = $matches[1]
$array[$i] = $time
}
$i++
}
내가 할 수있는 더 좋은 방법이 있습니까?
굉장! 나는 이것을 overthinking했다. 정말 고맙습니다. 이것은 완벽하게 작동합니다. – Koecerion
당신은 충분히 가깝습니다. 천만에요. –