Functions/Scripting/Add-StepTime.ps1

Function Add-StepTime
    {
    [CmdletBinding()]
    Param
        (
        # StepTimer Object
        [Parameter(Mandatory=$true)]
        [System.Collections.ArrayList]
        [AllowEmptyCollection()]
        $StepTimer,

        # Step Number
        [Parameter(Mandatory=$true)]
        [int]
        $StepNum,

        # Step Number
        [Parameter(Mandatory=$false)]
        [string]
        $StepDescription,

        # Step Start Time
        [Parameter(Mandatory=$false)]
        $StepTime = (get-date)
        )

    # Add Step to timer
    
    $NULL = $StepTimer.add([pscustomobject]([ordered]@{
        StepNum = $StepNum
        StepDescription = $StepDescription
        StepTime = $StepTime
        Interval = $Null
        }))

    # Add Interval Calculation
    $Interval = if($Stepnum -ge 1) {Get-StepTimespan -StepTimer $StepTimer -StartStepNum ([int]$StepNum-1) -EndStepNum $StepNum} else {[timespan]($StepTime-$Steptime)}
    $StepTimer[-1].interval = $Interval
    }