【发布时间】:2014-10-31 17:12:00
【问题描述】:
当我运行以下命令按 ID 列出日志时,它显示 Get-WinEvent : No events were found that match the specified selection criteria.
如何捕获此异常并显示一条简单的消息“未找到事件”。
我运行的命令-
Get-WinEvent -FilterHashtable @{LogName="Application";ID="191"}
我在下面尝试过,但无法正常工作-
try { Get-WinEvent -FilterHashtable @{LogName="Application";ID="191"}
}
catch [Exception] {
if ($_.Exception -match "No events were found that match the specified selection criteria") {
Write-Host "No events found";
}
}
请帮忙。谢谢
【问题讨论】:
标签: powershell powershell-2.0 powershell-3.0 powershell-ise