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!
>>
>>
>