2014-02-12 7 views
0

한 서버에서 월요일부터 금요일까지 오후 5시에서 오후 10시 사이에 이벤트를 가져 오는 방법.하나의보기에서 여러 날짜, 사용자 정의 필터링, 여러 로그 '이벤트

이렇게하면 특정 날짜의 시간 범위에 대한 이벤트가 제공됩니다.

Get-EventLog -LogName system | Where-Object {$_.TimeWritten -ge "2/5/14 00:00" -and $_.TimeWritten -le "2/7/14 00:00"}

어떻게 할 수있는 I 다음, 하나 개의보기에 여러 개의 로그에서 동시에 일종의 사용자 정의 필터링 이벤트. 이 방법은 내가이 권리를 읽고있다 경우에 대한 로그를 빗질 할 '수 - wineventlog'

$time = [System.Management.ManagementDateTimeConverter]::ToDmtfDateTime((Get-Date).AddHours(-12))

$sys = Get-WmiObject -Class win32_ntlogevent -filter "logfile = 'System' AND Sourcename = 'Srv' AND TimeGenerated>='$time'"|select -First 10

$app = Get-WmiObject -Class win32_ntlogevent -filter "logfile = 'Application' AND eventType < '3' AND TimeGenerated>='$time'"|select -First 10

$($sys + $app)|sort TimeWritten -Descending|select -Property logfile,EventCode,sourcename, Message| ft -AutoSize

답변

1

작동하지 않습니다 월요일부터 금요일까지 매일 밤 5 시부 터 10 시까 지 입장합니다. 이를 위해 Get-EventLog를 사용하기 시작했습니다. 이 스크립트는 5 일 동안 지정된 시작 날짜부터 반복하고 매일 5PM에서 10PM까지 필터에 설명 된대로 로그를 가져옵니다. 또한 LogFile 요소가 시스템 또는 응용 프로그램 로그에서 온 경우 상태로 각 항목에 추가합니다.

$StartDate = Get-Date "2/5/14" 
$TargetComputer = "BP1XEUTS399" 
$Logs = @() 
For($i=0;$i -lt 5;$i++){ 
    $TargetDate = $StartDate.AddDays($i) 
    $From = $TargetDate.AddHours(17) 
    $To = $From.AddHours(5) 

    #Remember what Error Actions is currently set to, and then set it to silent to avoid errors thrown when no log entries are found due to filters 
    $CurErrAct = $ErrorActionPreference 
    $ErrorActionPreference = "SilentlyContinue" 

    $Sys = Get-EventLog -Log System -After $From -Before $To -Source "Srv" 
    $Sys|%{$_|Add-Member -MemberType NoteProperty -Name "LogFile" -Value "System"} 
    $Apps = Get-EventLog -Log Application -ComputerName $TargetComputer -After $From -Before $To -EntryType Error,Warning 
    $Apps|%{$_|Add-Member -MemberType NoteProperty -Name "LogFile" -Value "Applications"} 
    $Logs += $Sys 
    $Logs += $Apps 

    #Set Error Actions back to what it was. 
    $ErrorActionPreference = $CurErrAct 
} 
$Logs|FT -autosize LogFile,EntryType,Source,Message 

몇 노트

, 난 당신이 밀접하게 내가 할 수있는 등의 질문에 무엇을했다 복제, 그래서 당겨지는 시스템 로그는 로컬 시스템의 로그입니다. 응용 프로그램 로그는 원격 컴퓨터에 있습니다. 동일한 컴퓨터에서 시스템 로그를 가져 오려면 $Sys = Get-EventLog 줄에 -ComputerName $TargetComputer을 추가하십시오.

+0

간체로 지정하십시오. 'foreach는 ($ 전에서 $ (5..7)) {$ C = @() $ A = GET-은 EventLog -LogName 시스템 - 후 "$ 내가 2014년 1월 16시 반"-before "$ 내가 2014년 1월 20시"-source SRV $의 C + = $ A $ B = GET-이벤트 로그 -LogName 응용 프로그램 - 후 "$ 내가 2014년 1월 16시 반"-before "$ 내가 1월 2014 20:00 "-EntryType 오류 | {$ _ 소스 -notmatch '프레임'.} $ C + = $ B를 $의 C | -Descending 종류의 TimeWritten | FT는 입력 유형, TimeWritten, 소스, 메시지}' Thanks..I 수를 -autosize 코멘트에서 형식화 권리를 결코 얻지 말라. –