![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Trap about Gwmi I use the following statement and the computer is off,but it can't trap the error that the gwmi generats(the error is "the RPC server is unavailable). trap{"ERROR"} $a = gwmi -class win32_networkadapter -computer "My_Dead_Computer_Name" Is this the problem of error scope ? Thanks a lot! |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Trap about Gwmi As this does not generate an exception, the error is catched by the CMDlet, it will not trigger the Trap. you can use parameters to fill the errorvariable and erroraction to supress message. PoSH> gwmi -class win32_networkadapter -computer foo -ev fooerror -ea SilentlyContinue PoSH> $fooerror Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA) At line:1 char:5 + gwmi <<<< -class win32_networkadapter -computer foo -ev fooerror -ea SilentlyContinue Greetings /\/\o\/\/ "HungYuWu" <HungYuWu@discussions.microsoft.com> wrote in message news:241808BB-FD1E-4B24-812B-9A789FC364A5@microsoft.com... >I use the following statement and the computer is off,but it can't trap the > error that the gwmi generats(the error is "the RPC server is unavailable). > > trap{"ERROR"} $a = gwmi -class win32_networkadapter -computer > "My_Dead_Computer_Name" > > Is this the problem of error scope ? > > Thanks a lot! > > |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: Trap about Gwmi So when you are writing a cmdlet, what is the best practice? Swallow all the exceptions the way Get-WmiObject does? //Andrew /\/\o\/\/ [MVP] wrote: > As this does not generate an exception, the error is catched by the > CMDlet, it will not trigger the Trap. > you can use parameters to fill the errorvariable and erroraction to > supress message. > > PoSH> gwmi -class win32_networkadapter -computer foo -ev fooerror -ea > SilentlyContinue > > PoSH> $fooerror > Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: > 0x800706BA) > At line:1 char:5 > + gwmi <<<< -class win32_networkadapter -computer foo -ev fooerror -ea > SilentlyContinue > > Greetings /\/\o\/\/ > > "HungYuWu" <HungYuWu@discussions.microsoft.com> wrote in message > news:241808BB-FD1E-4B24-812B-9A789FC364A5@microsoft.com... >> I use the following statement and the computer is off,but it can't >> trap the >> error that the gwmi generats(the error is "the RPC server is >> unavailable). >> >> trap{"ERROR"} $a = gwmi -class win32_networkadapter -computer >> "My_Dead_Computer_Name" >> >> Is this the problem of error scope ? >> >> Thanks a lot! >> >> > |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| gwmi Win32_ScheduledJob | gm | IT Staff | PowerShell | 3 | 08-21-2008 04:31 AM |
| Re: gwmi values into variables | Kiron | PowerShell | 0 | 12-14-2007 07:04 PM |
| Get-EventLog vs gwmi -query | $hay | PowerShell | 4 | 01-30-2007 04:21 PM |
| Glitch with gwmi and where-object | gaurhoth | PowerShell | 2 | 11-22-2006 03:27 PM |
| gwmi to get folder and security info | Pete Gomersall | PowerShell | 5 | 05-21-2006 05:53 PM |