Windows 10 Random time delay between two batch commands

onlinegill

New Member
Hello,
I have a batch script and i would like to put random delay / wait time in minutes to run second command.
example :
run first command here
random wait between 5 to 30 minutes
run second command here


Thank You
 

Neemobeer

Windows Forum Team
Staff member
There is a sudo random number generated in a command line shell you can call timeout /t %random% however there is no way to control the value range which is a 32 bit int. You'd have to do some math to control the value to get a range of 5-30 minutes.

If you re-wrote the batch file into a Powershell script it's much easier to control that timing.

<command one>
$wait_time = Get-Random -Minimum 300 -Maximum 1800
Start-Sleep -Seconds $wait_time
<command two>
 
Top