Windows Vista Forums

Trap about Gwmi

  1. #1


    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

  2. #2


    /\\/\\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

  3. #3


    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

Trap about Gwmi

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Dual GWMI where statement Flowering Weeds PowerShell 0 18 Feb 2009
gwmi Win32_ScheduledJob | gm IT Staff PowerShell 3 21 Aug 2008
Re: gwmi values into variables Kiron PowerShell 0 14 Dec 2007
Get-EventLog vs gwmi -query $hay PowerShell 4 30 Jan 2007
Glitch with gwmi and where-object gaurhoth PowerShell 2 22 Nov 2006