Average Rating:

2.50 by 2 users.

48 Downloads, 236 Views

1 Comment(s)

Measure-CommandTime.ps1

By: Isaiah Jesch 21 Apr 2011 08:38 PM UTC in the category: Beginner Event 10

Description:

This script uses Measure-Command to report on the time it takes Start-Sleep to work. Results are measured in total milliseconds and are reported as the average of 5 runs.
<#
	.SYNOPSIS
		Uses the Measure-Command cmdlet to time the Start-Sleep cmdlet.
	
	.DESCRIPTION
		This script uses Measure-Command to report on the time it takes Start-Sleep to work. Results are measured in total milliseconds and are reported as the average of 5 runs.
		
	.EXAMPLE
		Measure-CommandTime.ps1
			
	.NOTES
		Name: Measure-CommandTime.ps1
		Author: Isaiah Jesch
		Created: 2011-04-21
		LastEdit: 2011-04-21 15:08
		
	.LINK
		http://blogs.technet.com/b/heyscriptingguy/archive/2011/04/15/the-2011-scripting-games-beginner-event-10-use-powershell-to-measure-time-to-complete-a-command.aspx
#>
	# Assigns a variable to hold the time for the Start-Sleep command.
	$s = 5
		
	# A foreach command is run with the $n variable containing the total number of times the command is run (derived from the second # in
	# the "#..#" part below.	
	foreach($n in 1..5) {
		# Assigns a variable to hold the Measure-Command cmdlet. 
		$Time = Measure-Command -Expression {Start-Sleep -Seconds $s} 
		}
	# The $average variable is assigned the value of totalmilliseconds from the output of the command above.
	$Average = $time.totalmilliseconds 
	
	# Writes the data from the measure-command above in the format requested for the event.
	Write-Output "Average time of $n runs of $s seconds is $average milliseconds."
	
Top

Comments:

4/23/2011 11:07 PM
Nice and simple and a good job on the Comment based help. For fun play with INVOKE-EXPRESSION and turning this puppy into an Advanced Function in your Profile or a module :)