WMIObject
(1)
TotalMilliSeconds
(1)
Directory
(1)
Siddaway
(1)
Belgium
(1)
Logicaldisk
(1)
Otherwize
(1)
Exitafter
(1)

timeout functionality

Asked By Fran
30-Jul-07 03:10 PM
Hi,

Is there a timeout facility when doing commands like get-wmiobject.
Sometimes when running scripts on hosts, I want it to timeout after 10
seconds.  I'm looking for something similar to the "expect" timeout.

Thanks in advance,

Get-WMIObject doesn't have a timeout facility.

Asked By Rich
30-Jul-07 03:18 PM
Get-WMIObject doesn't have a timeout facility.  I am not aware of a timeout
facility within PowerShell
--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk

You could play with new-timespan (and properties ... ,seconds, milliseconds, ..

Asked By Jean
30-Jul-07 06:02 PM
You could play with new-timespan (and properties ... ,seconds,
milliseconds, ...)

This one stops after 5 seconds :

$exitafter=5000 #milliseconds
$start=(get-date)
$startms=(new-timespan $start).TotalMilliSeconds
do{
if(
(new-timespan $start).TotalMilliSeconds-$startm `
-ge `
$exitafter-$interval
)
{break} #or {exit}
###CODE###
}while($true)

Regards,

--
Jean - JMST
Belgium

timeout functionality

Asked By Jean
30-Jul-07 06:13 PM
Sorry, this code instead :

$exitafter=5000 #milliseconds
$start=(get-date)
do{
if(
(new-timespan $start).TotalMilliSeconds `
-ge `
$exitafter
)
{break} #or {exit}
###CODE###
}while($true)


Regards,

--
Jean - JMST
Belgium
For some reason, this still didn't work.
Asked By Fran
31-Jul-07 04:38 PM
For some reason, this still didn't work.  I replaced ###CODE### with "gwmi
win32_logicaldisk -computer test_cluster".  It still hangs forever.  This
host is the "non-active" cluster.

Thanks,
I'd extracted the code from a bigger project, so what is needed is to break
Asked By Jean
31-Jul-07 05:33 PM
I'd extracted the code from a bigger project, so what is needed is to
break (or exit) at the end of the code otherwize you go in an infinite
loop.

Here is an "example" :

#---8<---
$exitafter=10000
$dir=get-wmiobject win32_Directory
$start=get-date
do{
$dir|%{
$_.Name
if(
(new-timespan $start).TotalMilliSeconds `
-ge `
$exitafter
)
{'***10 SECONDS ELAPSED***';break}
}
'***SCRIPT END***'
break
}while($true)
#---8<---


But i'm not sure this could help you as if I understand well you need
an asynchronous stuff (or an event) and that, just now, I don't know
how to do (and even if it's possible or exists).

Regards,

--
Jean - JMST
Belgium
timeout functionality
Asked By Jean
31-Jul-07 05:52 PM
Perhaps some informations here (i have not tested):

http://www.scriptinganswers.com/forum2/forum_posts.asp?TID=956

Regards,

--
Jean - JMST
Belgium
Post Question To EggHeadCafe