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

Querying Internal DNS for Host Record for iDRAC IPs

Copy / Paste for quick results: $domain='hooli.com'$records=Get-DnsServerResourceRecord -ZoneName $domain -ComputerName $env:USERDNSDOMAIN$records|?{$_.HostName -like '*drac*' -and $_.RecordType…

PowerShell: Set Virtual Machine Default Paths on Hyper-V Host of a Cluster

$newVirtualMachinePath='D:\VirtualMachines' $newVirtualHardDiskPath='D:\VirtualMachines' function getHyperVHostsInForest{ function includeRSAT{ $ErrorActionPreference='stop' [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 #$rsatWindows7x32='https://download.microsoft.com/download/4/F/7/4F71806A-1C56-4EF2-9B4F-9870C4CFD2EE/Windows6.1-KB958830-x86-RefreshPkg.msu' $rsatWindows7x64='https://download.microsoft.com/download/4/F/7/4F71806A-1C56-4EF2-9B4F-9870C4CFD2EE/Windows6.1-KB958830-x64-RefreshPkg.msu' $rsatWindows81='https://download.microsoft.com/download/1/8/E/18EA4843-C596-4542-9236-DE46F780806E/Windows8.1-KB2693643-x64.msu' $rsat1709 =…

Microsoft SQL AlwaysOn High Availability Cluster Management Tool

There are some bugs in the script. I'm too lazy to go back a fix…