header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
How to put a timed Loop on remote wmi query
Last Post 26 Jan 2009 11:13 AM by Steven Murawski. 2 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
edm365f31User is Offline
Basic Member
Basic Member
Posts:100
Avatar

--
19 Dec 2008 08:53 AM
    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
    Steven MurawskiUser is Offline
    Community Co-Director
    Basic Member
    Basic Member
    Posts:137

    --
    26 Jan 2009 07:57 AM
    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 )
    Steven MurawskiUser is Offline
    Community Co-Director
    Basic Member
    Basic Member
    Posts:137

    --
    26 Jan 2009 11:13 AM
    Ok.. after further testing and a note from Shay (http://blogs.microsoft.co.il/blogs/...natic/)... 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 )
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer