Add timeout parameter to Get-WmiObject - by Jason Hofferle

Status : 


Sign in
to vote
ID 645165 Comments
Status Active Workarounds
Type Suggestion Repros 4
Opened 2/18/2011 9:56:55 AM
Access Restriction Public


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:
Sign in to post a comment.
Posted by just say NO to PDF on 3/13/2017 at 9:44 AM
Anyone who doesn't see the need for this has never managed a large network.
Posted by DaneKan on 6/17/2016 at 8:05 AM
It's amazing that someone AT microsoft wrote a work-around in 2009 and 7 years later it still is not baked in?
Posted by cgsilver on 4/15/2016 at 5:56 AM
It's frustrating that after 5 years, still not an option not even in PS5 :(
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.