Thursday, August 13, 2015

PowerShell Tip : Logging time taken by a PowerShell script to complete.

 

Do you wonder sometime, that how much time you script it taking to complete, or, when you have started the script and then it finished.

I love to see it, and I use a very simple  way to monitor it.

The trick is to create a variable in the first live on the script and save the Get-Date info, and in the end of the script create another variable and save the same Get-Date information to it , and then minus the start date variable with the end date and Voila! you will get the information.

  $startTime = Get-date

 Get-ChildItem c:\

 $endTime = Get-Date

 $endTime - $startTime

 

Aman Dhally - Manya Kaur

 

Aman Dhally - Manya Kaur

Thanks for your time.

Animated_peace_on_earth_hg_blk

Regards.
Aman Dhally
If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube channel for PowerShell video tutorials. You can download all of my scripts from “Microsoft TechNet Gallery”.

4 comments:

  1. Replies
    1. Yup, we can use that too :) , it's just an another way to do it ;)

      Delete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. Measure-Command {ls c:}

    ReplyDelete

Note: Only a member of this blog may post a comment.