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,
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. 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
"Frank" wrote:
> 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,
>
>
> 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,
You could play with new-timespan (and properties ... ,seconds,
milliseconds, ...)
This one stops after 5 seconds :
#---8<---
$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)
#---8<---
Regards,
--
Jean - JMST
Belgium
> This one stops after 5 seconds :
Sorry, this code instead :
#---8<---
$exitafter=5000 #milliseconds
$start=(get-date)
do{
if(
(new-timespan $start).TotalMilliSeconds `
-ge `
$exitafter
)
{break} #or {exit}
###CODE###
}while($true)
#---8<---
Regards,
--
Jean - JMST
Belgium
I think you need to check Don Jones's "IsManageable" function.
http://blog.sapien.com/current/2007/...anageable.html
Shay
http://scriptolog.blogspot.com
>> 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,
>>
> You could play with new-timespan (and properties ... ,seconds,
> milliseconds, ...)
>
> This one stops after 5 seconds :
>
> #---8<---
> $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)
> #---8<---
>
> Regards,
>
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,
"Jean" wrote:
> > This one stops after 5 seconds :
>
> Sorry, this code instead :
>
> #---8<---
> $exitafter=5000 #milliseconds
> $start=(get-date)
> do{
> if(
> (new-timespan $start).TotalMilliSeconds `
> -ge `
> $exitafter
> )
> {break} #or {exit}
> ###CODE###
> }while($true)
> #---8<---
>
>
> Regards,
>
> --
> Jean - JMST
> Belgium
>
>
>
> 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.
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
> 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).
Perhaps some informations here (i haven't tested):
http://www.scriptinganswers.com/foru...ts.asp?TID=956
Regards,
--
Jean - JMST
Belgium
| Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| session timeout? | Don | Live Mail | 0 | 02 Apr 2009 |
| UAC Timeout ?!? | Sven K | .NET General | 2 | 23 Oct 2008 |
| WebService and Timeout | shark | .NET General | 3 | 05 May 2008 |
| TabExpansion Timeout | blake.ryan@gmail.com | PowerShell | 0 | 01 Dec 2006 |
| Get-WmiObject Timeout? | gaurhoth | PowerShell | 1 | 23 Nov 2006 |