Summary

This script is an example of how to calculate the estimated completion time of a foreach loop.  The primary function can be called from a foreach loop to display a progress bar with estimated completion time.

The example script will simulate a task executing in a foreach loop by randomly sleeping for .5 to 1 second during each iteration of the foreach loop.  Optionally the script will record each time the function estimates the script completion time, then will display how many times it guessed each specific completion time.

 

Example:

This example will run the script with simulated workload and show the calculated values when complete.

 

PowerShell
Edit|Remove
.\CalculateRemainingExecutionTime.ps1 -ShowCalculatedTimes