Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Trap about Gwmi

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 03-21-2007   #1 (permalink)
HungYuWu
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 SpecsSystem Spec
Old 03-21-2007   #2 (permalink)
/\\/\\o\\/\\/ [MVP]
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 SpecsSystem Spec
Old 03-21-2007   #3 (permalink)
Andrew Savinykh
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 SpecsSystem Spec
Closed Thread

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


Vistax64.com 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 2005-2008

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 47 48 49 50 51