Try-Catch 无法捕获非终止错误 'hresult'
Try-Catch cannot catch non-terminating error 'hresult'
我需要捕获当前正在输出的跟随错误:
ERROR ( hresult:80070425, message:Command execution failed.) The
service cannot accept control messages at this time.
来自我的 PowerShell 脚本片段,目前没有捕捉到错误:
Try{
appcmd start apppool /apppool.name:DefaultAppPool
}Catch{
#$ErrorMessage = $_.Exception.Message
#$FailedItem = $_.Exception.ItemName
Write-Host "AppPool cannot start." -BackgroundColor Red
}
我错过了什么吗?我希望错误消息尽可能具体。如果有帮助,这是 IIS8.5。我引用了这些链接:1 | 2 | 3 | 4 | 5 |
您收到的错误消息可能来自 appcmd
,因此 不是 您可以捕获的 powershell 异常。您可以检查 $global:LastExitCode
以验证调用是否成功。
但是,还有一个 WebAdministration
powershell 模块有一个 Start-WebAppPool
cmdlet:
Import-Module WebAdministration
Start-WebAppPool -Name 'DefaultAppPool'
我需要捕获当前正在输出的跟随错误:
ERROR ( hresult:80070425, message:Command execution failed.) The service cannot accept control messages at this time.
来自我的 PowerShell 脚本片段,目前没有捕捉到错误:
Try{
appcmd start apppool /apppool.name:DefaultAppPool
}Catch{
#$ErrorMessage = $_.Exception.Message
#$FailedItem = $_.Exception.ItemName
Write-Host "AppPool cannot start." -BackgroundColor Red
}
我错过了什么吗?我希望错误消息尽可能具体。如果有帮助,这是 IIS8.5。我引用了这些链接:1 | 2 | 3 | 4 | 5 |
您收到的错误消息可能来自 appcmd
,因此 不是 您可以捕获的 powershell 异常。您可以检查 $global:LastExitCode
以验证调用是否成功。
但是,还有一个 WebAdministration
powershell 模块有一个 Start-WebAppPool
cmdlet:
Import-Module WebAdministration
Start-WebAppPool -Name 'DefaultAppPool'