Sybux
asked on
Try / Catch error during Powershell script
hi,
I'm running this little script :
&{
$myHosts
get-Stat -Entity $myHosts
}
trap [VimException]
{
Write-Error "fails"
}
I want to trap the error from get-stat but it's never catch.
Here is the output of the script :
Get-Stat : 14.03.2012 21:07:39 Get-Stat Object reference not set to a
n instance of an object.
At C:\vCheck6\test.ps1:3 char:10
+ get-Stat <<<< -Entity $myHosts
+ CategoryInfo : NotSpecified: (:) [Get-Stat], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownErr or,VMware. VimAutomat io
n.ViCore.Cmdlets.Commands. GetViStats
Any ideas are welcome !
I'm running this little script :
&{
$myHosts
get-Stat -Entity $myHosts
}
trap [VimException]
{
Write-Error "fails"
}
I want to trap the error from get-stat but it's never catch.
Here is the output of the script :
Get-Stat : 14.03.2012 21:07:39 Get-Stat Object reference not set to a
n instance of an object.
At C:\vCheck6\test.ps1:3 char:10
+ get-Stat <<<< -Entity $myHosts
+ CategoryInfo : NotSpecified: (:) [Get-Stat], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownErr
n.ViCore.Cmdlets.Commands.
Any ideas are welcome !
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.