Converting VBScript's Timer Function

Definition: Returns the number of seconds that have elapsed since 12:00 AM (midnight).

Timer

In VBScript the Timer function is typically used to determine how long it takes a script, function, or subroutine to execute. If that's what you want to do then you can use the Windows PowerShell Measure-Command Cmdlet to calculate elapsed time. The following command creates a For Next loop that runs from 1 to 100,000, writing each value of $a to the screen as it goes. Along the way, the Measure-Command Cmdlet is used to keep track of how long it takes for the command to finish:

measure-command {
    for ($a = 1; $a -le 100000; $a++) 
        {write-host $a}
                 }

When you run this command you should get back information similar to the following:

Days              : 0
Hours             : 0
Minutes           : 1
Seconds           : 9
Milliseconds      : 365
Ticks             : 693655925
TotalDays         : 0.000802842505787037
TotalHours        : 0.0192682201388889
TotalMinutes      : 1.15609320833333
TotalSeconds      : 69.3655925
TotalMilliseconds : 69365.5925

Return to the VBScript to Windows PowerShell home page