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: Install Windows Cluster Admin

# Install Microsoft Clustering ManagementFunction installClusteringManagment{ # Set PowerShell Gallery as Trusted to bypass prompts…

Set Permissions of NTFS/SMB Directories Recursively

# Set variables here$proxy="http://proxy:80"$directories="\\FILESERVER01\dept01$","\\FILESERVER01\dept02$"$grantAccess="KIMCONNECT\SysAdmins"$access="Full"# Run as$username = "kimconnect\kim"$password = "PASSWORD"#$username = "kimconnect\"+(Read-Host -Prompt 'Input the…

Reset Internet Explorer Settings Script

You can reset Internet Explorer settings to return them to the state they were in when…