Home Dashboard Directory Help
Search

Add timeout parameter to Get-WmiObject by Jason Hofferle


Status: 

Active


53
0
Sign in
to vote
Type: Suggestion
ID: 645165
Opened: 2/18/2011 9:56:55 AM
Access Restriction: Public
1
Workaround(s)
view

Description

Get-WmiObject is commonly used to collect information from a list of remote computers. Most of the time this works correctly, but if WMI is broken on the remote system it can cause a script to hang.

A workaround that implements a custom function was posted here:
http://blogs.msdn.com/b/dmuscett/archive/2009/05/27/get_2d00_wmicustom.aspx
Details
Sign in to post a comment.
Posted by CoffeineNerd on 7/3/2014 at 12:46 PM
It is frustrating not to have a simple -Timeout <seconds> to this important function when doing remote WMI queries.
Posted by Robert Heinig II on 8/14/2012 at 12:59 AM
IMHO, *if* you have good reason to script remote wmi queries, then it's highly likely that you'll loop over e.g. an AD (objectCategory=Computer) query, and almost assured you'll run into this problem.

The current implementation *will* time out for machines that are simply offline, *but* the error is not trappable with either -ErrorVariable or try{} catch {}. And that is the real embarrassment. [sarcasm] Most logical reaction? Drop powershell altogether and use c# express instead.[/sarcasm]
Posted by irussb on 10/14/2011 at 4:19 AM
I'm new to PowerShell and have made good progress in the last 5 weeks, until I hit this barrier head-on. I couldn't quite believe that there was no timeout option built-in to Get-WmiObject. I'm now faced with re-writing all of my scripts to include Daniele's (fantastic) workaround, but will keep my original copies in the hope that PowerShell v3.0 includes this (IMO fundamental) enhancement.
Posted by Mike Koehler on 9/18/2011 at 5:39 PM
This is a vital improvement to Get-WmiObject. When you are managing a large inventory of servers there is always a few where WMI is broken. Having the script hang forever defeats the whole purpose of powershell.

While we are at it we need to file something to encourage getting WMI fixed so we wouldn't need to deal with its failures.
Sign in to post a workaround.
Posted by CoffeineNerd on 7/3/2014 at 12:48 PM
This link has 2 options for alternatives, none of them elegant but may help a little.
http://stackoverflow.com/questions/9710512/timeout-get-wmiobject-cmdlet