2

What I am looking for is a Powershell version of this: Time condition loop in shell

So I can have something like this:

if(Condition -eq True){
    for(3000){         #I assume it will use milliseconds
        COMMAND
    }
}

EDIT: This will not be running continuously, unlike the example, it could be triggered at any time, and when the time ends, it should exit out of the loop and resume the program as normal.

Community
  • 1
  • 1
Freddie R
  • 377
  • 5
  • 15

1 Answers1

5

This is one way, with some simple 100ms throttling:

$sw = [Diagnostics.Stopwatch]::StartNew()

while ($sw.ElapsedMilliseconds -lt 3000)
{
    #COMMAND HERE
    Write-Host "ElapsedMilliseconds $($sw.ElapsedMilliseconds)"
    Start-Sleep -Milliseconds 100
}
$sw.Stop()
TechSpud
  • 3,418
  • 1
  • 27
  • 35