0
$ Pingy = Get-WmiObject에서 일반적인 예외를 잡으려고 시도하는 중 Win32_PingStatus -f "Address = '$ Fip'"[예외] 캐치 [System.Exception] catch하고 그냥 잡으려고했습니다. powershell 버전 2 사용.일반적인 예외 잡기 - powershell
질문은 Get-WmiObject에 대한 일반적인 예외를 잡는 방법입니다. 나중에 pingSuccess가 true 또는 false인지 확인하여 진행 방법을 결정합니다. 지금은 항상 pingSuccess를 true로 설정합니다. 예외가 발생하면 원하지 않습니다. 심지어
Win32_PingStatus -f "Address='somenonsehere'"
오류가 발생하지 않습니다처럼
function Ping
{
param($Fip)
try
{
$Pingy = Get-WmiObject Win32_PingStatus -f "Address='$Fip'"
return New-Object PSObject -Property @{
pingSuccess=$true
ex=$null
code=$Pingy.statuscode
}
}
catch [System.Exception]
{
return New-Object PSObject -property @{
ex=$_.Exception
pingSuccess=$false
}
# write-host $exc.gettype()
# write-host $exc.message
# write-host $exc.innerException
}
}
안녕하세요 : 예를 들어 ? –
위 업데이트^ – user3700372
'get-help about_return' .. try에서 함수를 항상 종료하면 catch가 실행되지 않습니다. – Cole9350