Register
: :
Login
Home
Forums
Blogs
Podcast
Directories
Scripts
Downloads
Community
User Group Support
Learning Resources
We have a new sponsor! Introducting
Pragma Systems
. See the home page for details.
Unanswered
Active Topics
Forums
Search
Members
Forums
>
Using PowerShell
>
General PowerShell
How to put a timed Loop on remote wmi query
Last Post 26 Jan 2009 07:13 PM by
smurawski
. 2 Replies.
Sort:
Oldest First
Most Recent First
Prev
Next
You are not authorized to post a reply.
Author
Messages
edm365f31
New Member
Posts:98
19 Dec 2008 04:53 PM
Is there a way to put a Time on how long a wmi query to a remote box will stay in case a wmi is hang on a remote box, so it just go to the next box on the list.
I have encountered this a lot that a remote box is pingable but wmi is hang and the script will just sit there.
$erroractionpreference = "SilentlyContinue" does not work
also tried inserting winmgmt reset on script it helps but I still get stuck at times.
(get-service -comp $strComputer |where {$_.servicename -eq "winmgmt"}).stop()
I am thinking about putting a time limit when it queries a box once it hit lets say 30 secs it will break up and move on to the next bxo on the list.
Thnx
smurawski
Community Co-Director
Basic Member
Posts:137
26 Jan 2009 03:57 PM
You can put a timeout on the WMI query.
There is a timeout option in the wmi object, but you have to go through the psbase property.
Example:
$WMI = [wmi]''
$WMI.psbase.options.timeout = 20000000 #time in ticks - 2 seconds
$WMI.psbase.path = "\\computername\root\cimv2:Win32_Service.Name='BITS'"
After setting the path, when you access the variable $wmi, the query will be evaluated.
Steven Murawski
Blog ( blog.usepowershell.com )
Co-Host - Mind of Root ( www.mindofroot.com )
Director - Research and Development for ProPhoenix ( www.prophoenix.com )
smurawski
Community Co-Director
Basic Member
Posts:137
26 Jan 2009 07:13 PM
Ok.. after further testing and a note from Shay (http://blogs.microsoft.co.il/blogs/ScriptFanatic/)... I found that the timeout property is specifically for enumerating a collection. So, depending on the kind of timeout that you are experiencing, this may or may not work.
There is another setting, $WMI.psbase.scope.options.timeout, that could affect the enumeration results.
You could also try using the [WMISearcher] accelerator. You can set the timeout option on that in several places. Additionally, there is a property under the Options property of the WMISearcher called ReturnImmediately. By default it should be set to true and should keep the query from hanging. I could not find the equivalent in the WMIClass accelerator.
One:
$searcher = [WMISearcher]
$searcher.options.timeout = '0:0:2' # 2 seconds, string is cast to a timespan object/alternative to using ticks
Two:
$searcher = [WMISearcher]
$searcher.scope.options.timeout = '0:0:2'
The fourth option is not PowerShell specific, but might help. On the target machine, run dcomcnfg.exe and navigate to the Component Services->My Computer. Right click and choose properties. On the options tab, there is a timeout (in seconds) for DCOM transactions. Fiddle with that at your own risk. :)
Steven Murawski
Blog ( blog.usepowershell.com )
Co-Host - Mind of Root ( www.mindofroot.com )
Director - Research and Development for ProPhoenix ( www.prophoenix.com )
You are not authorized to post a reply.
PowerShellCommunity.org
--Community Announcements and Assistance
--Completely Unrelated
--User Groups
--Community Business
----Suggestion Box
Using PowerShell
--General PowerShell
--Books, Tools, and Videos
--Exchange Server
--Active Directory
--System Center Family
--Non-Microsoft Products
--SharePoint
--SQL Server
--Working with .NET
--Peer Review
--Testing, Testing...
PowerShell Development
--Cmdlet Development
--PSDrive Provider Development
--Hosting the Shell
Looking Ahead
--Using PowerShell v2.0
--Developing for PowerShell v2.0
Forums
>
Using PowerShell
>
General PowerShell
Active Forums 4.1
Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008