How long does my PowerShell script take to run?

Do you ever want to know how long it takes to run a PowerShell script? Most of my scripts run for a few minutes or less, so I measure the time it takes in seconds. I round two decimal places in the example below.

At the top of my script I put the start variable. This is the start time using Get-Date.
$startTime = (Get-Date)

The second to last line, I put the end variable. Again it is using Get-Date.
$endTime = (Get-Date)

The last line outputs the difference between the start and end Get-Date variables.
write-host "Elapsed Time: $([math]::Round(($endTime-$startTime).totalseconds, 2)) seconds"

Here is an example in PowerShell: