Run batch file every x seconds using PowerShell

I would like to use a Windows PowerShell script to run a batch file every x seconds. So the same batch file runs over and over.

I looked, but can not find what I am looking for. This is for something that I want to run on a Windows XP machine. I often used the Windows Scheduler for something like that, but for some reason, the Windows Scheduler only works once ... Then nothing more. I also do not want to have the batch file call itself, because it will fail after running it so many times.

+7
windows powershell
source share
1 answer

Just put the batch file call into the while loop, for example:

$period = [timespan]::FromSeconds(45) $lastRunTime = [DateTime]::MinValue while (1) { # If the next period isn't here yet, sleep so we don't consume CPU while ((Get-Date) - $lastRunTime -lt $period) { Start-Sleep -Milliseconds 500 } $lastRunTime = Get-Date # Call your batch file here } 
+13
source share

All Articles