문제

나는 건설 powershell 기능 그래서를 쿼리할 수 있습니다 여러 컴퓨터에 이벤트 로그입니다.Ive 복사한 코드는 아래는 내가 도움이 필요합니다.지 않는 경우 보내 id,내가 원하는 스크립트를 찾는 모든 이벤트 ID 의,어떻게 수행할 수 있습니까 이?

#this would be the parameter part of the script
[String]$ComputerName = $env:COMPUTERNAME#Current computer 
[String[]]$EventLogNames=@("Application","System")#Main eventlogs 
[int[]]$EventIds = 1 #Event Ids 
[System.DateTime[]]$EventStartDate = (((Get-Date).addDays(-2)).date)#date 10 days ago 
[System.DateTime[]]$EventEndTime = (Get-Date)#date 10 days ago 

#This fits in the process section
$EventCritea = @{logname = $EventLogNames; StartTime=$EventStartDate; EndTime=$EventEndTime; ID=$EventIds}
Get-WinEvent -ComputerName $ComputerName -FilterHashTable $EventCritea  -ErrorAction SilentlyContinue
도움이 되었습니까?

해결책

첫째,기타 질문 수정의 유형 $EventStartDate$EventEndTime.

이 질문에 대해서는:를 구축 hashtable 점진적으로:

$filter = @{logname = $EventLogNames; StartTime=$EventStartDate; EndTime=$EventEndTime}

if ($EventIds -ne $null -and $EventIds.Length -gt 0) {
  $filter.ID=$EventIds
}

Get-WinEvent -ComputerName $ComputerName -FilterHashTable $filter #...
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top