Last weeks I spent most of my time preparing the presentation for TechDays 2012. Not surprisingly – I was talking about PowerShell v3 in new Windows 8. As there was strict requirement for presentation length (60 minutes) I had to plan carefully. Therefore I decided to create small script to measure my presentation length. It reports time for every topic I discussed.

Function uses simple comparison of two time stamps with New-TimeStamp cmdlet. Then it just shows it in console but also writes it to text file for future reference. Everything is hardcoded in function now. Maybe will change it in future, now it’s here just for future reference.

function Show-PresentationLength
{
    BEGIN
    {
        $Global:Presentation=@{}
        $path = "$env:USERPROFILE" + '\Documents\PresentationTiming.txt'
        Out-File -FilePath $path -InputObject (Get-Date) -Append
    }

    PROCESS
    {
        Read-Host "Start ($_)"
        $start = Get-Date
        Write-Host "Running $_ ..." -Fore Yellow -NoNewline
        Read-Host "Stop ($_)"
        $end = Get-Date

        $cycle = New-TimeSpan -Start $start -End $end

        $Global:Presentation[[int]$_]=$cycle
        $Presentation.GetEnumerator() |% -Begin {$sum=0} -Process {$sum+=$_.Value}

        "Time ($_): {0:mm}:{0:ss}" -f $cycle
        Out-File -FilePath $path -InputObject "Time ($_): $cycle of ($sum)" -Append
    }

    END
    {
        Clear-Host
        "Total Time: {0:hh}:{0:mm}:{0:ss}" -f $sum
        Out-File -FilePath $path -InputObject "Total Time: $sum" -Append
        foreach ( $s in $($Global:Presentation.GetEnumerator() | Sort Name) )
        {
            "Slide {0}: {1:mm}:{1:ss}" -f $s.Name, $s.Value
        }
    }
}

When I wanted to test length of some topic I discussed, I just started it this way (checking time for first three slides):

PS C:\> 1..3|Show-PresentationLength
Start (1):
Running 1 …Stop (1):
Time (1): 00:10
Start (2):
Running 2 …Stop (2):
Time (2): 00:14
Start (3):
Running 3 …Stop (3):
Time (3): 00:14
Total Time: 00:00:39
Slide 1: 00:10
Slide 2: 00:14
Slide 3: 00:14

And can also see result in mentioned file (it also contains history).

BTW: Also because of this script I was able to finish both my presentations on time :)