Running into a problem using Invoke-WmiMethod
in a script, which when run against some computers just hangs. What I'd like to do is execute the command and if it does not return within some defined period of time (say 60 to 120 sec's) then move on (logging the bailout to a file as well.) The only way I currently know to try to do this is using the -AsJob
parameter; however, when I try that, the spawned job immediately fails (even against computers where the Invoke-WmiMethod
statement is working without the -AsJob
parameter added.) Other WMI-related cmdlets do work against these problem machines, so I don't think it's a auth or DCOM problem.
Anyways, are there other ways of setting a timeout on a statement in a script that I can try?
Using SQL Server Management StudioIn Object Explorer, right-click a server and select Properties. Click the Connections node. Under Remote server connections, in the Remote query timeout box, type or select a value from 0 through 2,147,483,647 to set the maximum number seconds for SQL Server to wait before timing out.
Stops any statement that takes over the specified number of milliseconds. The statement_timeout value is the maximum amount of time a query can run before Amazon Redshift terminates it. This time includes planning, queueing in workload management (WLM), and execution time.
The timeout period elapsed prior to completion of the operation or the server is not responding.
Troubleshoot timeout expired errorsIncrease the connection-timeout parameter. If you use an application to connect to SQL Server, increase the relevant connection-timeout parameter values and check whether the connection eventually succeeds. For example, if you use System. Data.
Hmm, not sure why Invoke-WmiMethod
fails but perhaps Invoke-Command
will work (worth a quick try I guess) e.g.:
$job = Invoke-Command -cn $computers { Invoke-WmiMethod ... } -AsJob
Wait-Job $job -Timeout 60
This does assume you have enabled remoting on all the remote computers and that they are running PowerShell 2.0. Make sure you run this from an elevated prompt if on Vista/Windows 7 or as admin on XP.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With