param( [Parameter(Mandatory=$true)] [string]$LogName ) if (-not (Get-WinEvent -ListLog $LogName -ErrorAction SilentlyContinue)) { Write-Error "Event log '$LogName' does not exist." exit 1 } $start = (Get-Date).AddHours(-1) # 1:Critical, 2: Error, 3: Warning, 4: Information, 5: Verbose $count = (Get-WinEvent -FilterHashtable @{ LogName = $LogName Level = 1,2 StartTime = $start } -ErrorAction SilentlyContinue).Count Write-Output $count exit 0