Successfully added
PowerShell
by Rick
Showing Elapsed Time in PowerShell Scripts
In PowerShell, you can show elapsed time using a simple timer script. Start by capturing the current time when your script begins with $StartTime = $(Get-Date)
. Then, calculate the elapsed time by subtracting the start time from the current time: $elapsedTime = $(Get-Date) - $StartTime
. Format the elapsed time into hours, minutes, and seconds using the "{0:HH:mm:ss}"
format and apply it to a DateTime object: $totalTime = "{0:HH:mm:ss}" -f ([datetime]$elapsedTime.Ticks)
.
$StartTime = $(Get-Date)
# Your script here
$elapsedTime = $(Get-Date) - $StartTime
$totalTime = "{0:HH:mm:ss}" -f ([datetime]$elapsedTime.Ticks)
Write-Host "Total elapsed time: $totalTime"
For more details and discussions, you can refer to this Stack Overflow post.
Referenced in:
Comments(3)
anton99228334234235
3/21/2024 3:51:07 PMPillsKnime
3/21/2024 12:15:39 PMJamesbiofe
3/21/2024 1:26:03 AM