Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute statement with timeout?

Tags:

powershell

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?

like image 645
Will Dennis Avatar asked Mar 24 '11 03:03

Will Dennis


People also ask

How do you set a timeout in SQL query?

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.

What is statement timeout?

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.

What is execution timeout in SQL Server?

The timeout period elapsed prior to completion of the operation or the server is not responding.

How do I fix execution timeout expired?

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.


1 Answers

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.

like image 180
Keith Hill Avatar answered Oct 04 '22 06:10

Keith Hill