Posted On November 4, 2019

PowerShell: Play with Time

kimconnect 0 comments
blog.KimConnect.com >> Codes >> 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 *

Related Post

PowerShell: Find Duplicate RDP Sessions on All Remote Desktop Servers Discovered Within the Domain

There's this module called 'PSTerminalServices' that has a method to collect active sessions on all…

PowerShell: Search Windows Event Logs

# searchWindowsEventsLog.ps1 $computername=$env:computername $logType='Security' $eventId=4732 $daysBack=365 $limit=9999 $messageLike="*Remote Desktop Users*" function searchWindowsEvents{ param( $computername=$env:computername $logType='Security'…

Centos 5.3 Server preparation for web hosting

These are compatible Repositories: FreshRPMS, Dries, NewRPMS and PlanetCCRMA   Note: to update PHP and…