Tuesday 5 May 2009

Clear-Stopwatch.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script displays the use of the Reset method in a StopWatch object. 
  4. .DESCRIPTION 
  5.     This script calls the StartNew static method to create and start a new  
  6.     stopwatch object, and displays the current values for the stop watch. The  
  7.     stopwatch is then reset using the Reset method, then the current values are displayed.  At completion, 
  8.     the stopwatch is stopped and all counters are zero. 
  9. .NOTES 
  10.     File Name  : Clear-Stopwatch.ps1 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell V2 CTP3 
  13. .LINK 
  14.     This script posted to: 
  15.         http://www.pshscripts.blogspot.com 
  16.     MSDN Sample posted at: 
  17.         http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.reset.aspx 
  18. .EXAMPLE 
  19.     PSH [C:\foo]: .\Clear-Stopwatch.ps1 
  20.     StopWatch object before reset: 
  21.     IsRunning           : True 
  22.     Elapsed             : 00:00:00.0039085 
  23.     ElapsedMilliseconds : 3 
  24.     ElapsedTicks        : 57153 
  25.     StopWatch object after reset: 
  26.     IsRunning           : False 
  27.     Elapsed             : 00:00:00 
  28.     ElapsedMilliseconds : 0 
  29.     ElapsedTicks        : 0 
  30. #> 
  31.    
  32. ## 
  33. #  Begin script 
  34. ## 
  35. # Create a stop watch object and auto start it 
  36. $sw = [system.Diagnostics.Stopwatch]::StartNew() 
  37.    
  38. # Now get current elapsed time: 
  39. "StopWatch object before reset:" 
  40. $sw | fl * 
  41.    
  42. # Now reset 
  43. $sw.reset() 
  44.    
  45. # Observe Results 
  46. "StopWatch object after reset:" 
  47. $sw | fl * 
  48. # End script 

No comments: