Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

How do I get past "WMI Connection failed" errors

by StarkRavingCalm (Sexton)
on Feb 12, 2009 at 19:10 UTC ( #743434=perlquestion: print w/replies, xml ) Need Help??
StarkRavingCalm has asked for the wisdom of the Perl Monks concerning the following question:

Hoping this is an easy one...

I have a script that I am using to query Windows machines for Hotfixes. I am running it as domain admin. When it connects to a machine, I get the data I am looking for. But, if it hits a machine that is down (I verify with a ping), I get "WMI Connection failed" errors and then it stops. I have a warn statement in there but it does not continue.

Here is the relevant data in the script.(The script itself is HUGE as it does some munging at the end before it writes to a file)

my $objWMIService = Win32::OLE->GetObject("winmgmts:\\\\$computer\\ro +ot\\CIMV2") or warn "WMI connection failed.\n"; my $colItems = $objWMIService->ExecQuery("SELECT * FROM Win32_Quick +FixEngineering", "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly);

Can anyone help me get past these errors?

Replies are listed 'Best First'.
Re: How do I get past "WMI Connection failed" errors
by Corion (Pope) on Feb 12, 2009 at 19:15 UTC

    Most likely you can catch the error using an eval block. Otherwise, I'd just ping the machine before trying to connect to it:

    select responsetime from Win32_PingStatus where Address = ''

      That could work as a temporary work around.

      Right now I am reading each machine name from an array, but I ultimately want reading each server in real time from the domain.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://743434]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2018-08-17 09:44 GMT
Find Nodes?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:

    Results (176 votes). Check out past polls.