Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - how to work error interception

Reply
 
Old 09-10-2008   #1 (permalink)
pg


 
 

how to work error interception

hi,

i have a script which control space disk on my servers(more 200). to do it i
use wmi object. on some machine, my wmi is out and i have an error message
"get-wmiobject : access is denied ..."

how can i intercept that ?

thanks for all !






My System SpecsSystem Spec
Old 09-10-2008   #2 (permalink)
Kiron


 
 

RE: how to work error interception

Get-WmiObject exceptions are usually non-terminating, you cannot trap
non-terminating exceptions. You can stop execution when a non-terminating
exception is raised by setting Get-WmiObject's parameter -ErrorAction (or
-ea) to 'Stop' (or 1), then a Trap statement will trap the
[Management.Automation.ActionPreferenceStopException] exception. The
non-terminating error is available in your trap as the second element of the
$error collection, i.e. $error[1].

trap [Management.Automation.ActionPreferenceStopException] {
# handle the exception
continue # exit the trap
}
gwmi ... -ea 1

--
Kiron
My System SpecsSystem Spec
Old 09-10-2008   #3 (permalink)
Kiron


 
 

RE: how to work error interception

Correction:
"The non-terminating error is available in your trap as the second element
of the $error collection, i.e. $error[1]."

The non-terminating error is wrapped by the ActionPreferenceStopException,
which is available in the trap through the current pipeline object '$_'. At
least the non-terminating exception's message is appended to
ActionPreferenceStopException's message. This stuff is not documented, sorry
about 'my non-terminating' error, I was thinking 'theoretically'.


--
Kiron
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
spooler error gone - now can't get printer to work Vista print fax & scan
Error Trapping : doesn't work PowerShell
Error message. Do the instructions for OE work for this? Vista mail
HELP PLEASE I keep getting error 732 with VPN for work Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46