Quantcast
Channel: PowerShell Basics Archives - TechGenix
Viewing all articles
Browse latest Browse all 84

PowerShell Quick Tip: Track the time it takes for your scripts to run

$
0
0

When running PowerShell scripts it is always good to measure the time that your script is taking to complete any given task. I wrote a small function that you can use on your scripts at the start and end to accomplish this goal.

The function is simple, and we need to pass a variable. If the variable is empty, then it will receive the current time (Item 1). When we execute it a second time, it will compare the time difference to the variable (Item 2). The variable after the second run (Item 3) contains the time that it took in minutes, days, hours, and seconds.

PowerShell script time

The function to track the time it takes for your PowerShell script to run is comprised of two lines, as follows.

Function TrackTime($Time){
If (!($Time)) { Return Get-Date } Else {
Return ((get-date) - $Time)
}
}

The post PowerShell Quick Tip: Track the time it takes for your scripts to run appeared first on TechGenix.


Viewing all articles
Browse latest Browse all 84

Trending Articles