0
試圖從$ Pingy = Get-WmiObject Win32_PingStatus捕獲一般異常-f「Address ='$ Fip'」已嘗試捕獲[Exception],捕獲[System.Exception]並剛剛捕獲。使用powershell版本2.捕獲一般異常 - powershell
問題是如何捕獲Get-WmiObject的一般異常。代碼稍後檢查pingSuccess的真或假,以確定如何繼續。現在它始終將pingSuccess設置爲true,如果拋出異常,我不希望這樣做。
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 – Cole9350