Link to home
Start Free TrialLog in
Avatar of Sybux
SybuxFlag for Switzerland

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_UnknownError,VMware.VimAutomatio
   n.ViCore.Cmdlets.Commands.GetViStats

Any ideas are welcome !
ASKER CERTIFIED SOLUTION
Avatar of Joe Klimis
Joe Klimis
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial