# global variable to hold total (cumulative) execution time
$global:pshUse = New-TimeSpan
# holds the last command id
$global:lasdID
function Prompt{
# get the last command
$item = Get-History -Count 1
# don't add-up times when typing ENTER repeatedly
if($global:lasdID -ne $item.id){
$global:lasdID=$item.id
# get the last command execution time (timespan)
$diff = $item.EndExecutionTime-$item.StartExecutionTime
# add it to the global $pshUse
$global:pshUse = $global:pshUse.Add($diff)
# string format total execution time in HH:mm:ss
# and last command execution time in mm:ss.milliseconds
$title = "{0:T} , Last [{1:mm:ss.fff}]" -f [datetime]($pshUse.ticks),[datetime]($diff.ticks)
# update console title, show current directory,
# session execution time, and last command execution time
$host.UI.RawUI.WindowTitle = "{0} | Session Execution Time: {1}" -f $pwd,$title }
# write custom prompt with the last history command id
# each nested prompt level is indicated by an extra ">"
"PS {0}{1} " -f ($item.id+1), (">"*($NestedPromptLevel+1))}