PowerShell: Play with Time

1. Constructor:

$timer=[System.Diagnostics.Stopwatch]::StartNew()

2. Accessing a property

$totalSeconds=$timer.Elapsed.TotalSeconds

3. Output Time (Usage):

$hours=[math]::round($totalSeconds/3600,2)
write-host "It has been $hours hours."

4. Destructor (optional as the system automatically performs this task when session goes out of scope):

$timer.stop()

Leave a Reply

Your email address will not be published. Required fields are marked *