作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我运行以下命令按 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";
}
}
最佳答案
这是一个非终止错误,不会被 try
捕获/catch
.使用 -ErrorAction Stop
.
try { Get-WinEvent -FilterHashtable @{LogName="Application";ID="191"} -ErrorAction Stop
}
catch [Exception] {
if ($_.Exception -match "No events were found that match the specified selection criteria") {
Write-Host "No events found";
}
}
关于powershell - (Powershell) 捕获 "Get-WinEvent : No events were found"Get-WinEvent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26680036/
我是一名优秀的程序员,十分优秀!