Skip Ribbon Commands
Skip to main content

Quick Launch

Todd Klindt's home page > Todd Klindt's Office 365 Admin Blog > Posts > Time Operations in PowerShell with Measure-Command
October 25
Time Operations in PowerShell with Measure-Command

A couple of days ago I got an IM from a coworker asking me some upgrade questions. They were working in a test environment practicing everything before the Production upgrade. One of the questions was “Is there a way to see how long the mount-spcontentdatabase took?” I was so proud that they were testing things and timing things that I had to wipe a tear from my eye.

There are a couple of ways to skin this cat, but the first thing that jumped into my head was Measure-Command. Measure-Command is a cmdlet that measures how long it takes a scriptblock or a script to run. If you ever ran the old timethis.exe from the NT Resource Kit then you know what this is like. In this particular case the usage would look like this:

Measure-Command { Mount-SPContentDatabase –Name wss_content_portal –WebApplication http://portal.contoso.com }

If the Transcript is on (and it always should be, in my opinion) all the time information written out by Measure-Command will be in it, so it’ll be easy to find later on. The output from Measure-Command is a TimeSpan object so it has some obvious properties like Hour, Minute, Second, etc, so it’s easy to tailor the output to look however you want.

You can use this command the way my coworker did, to measure how long a command or script takes to execute. This could be testing the steps of an upgrade, or any other important task, like mass creation of site collections. Anything where you’ll need to provide management with time estimates. When you get better with PowerShell you’ll find there are often multiple ways to do the same task, especially when you start looping through objects and making decisions. When faced with multiple ways to do something it can often be tough to decide which way is best. I used to be a fan of just flipping a coin, or doing it the PowerShell way; “head”,”tails” | Get-Random. (PowerShell really likes “heads”) Now with Measure-Command we can see how long each way takes and let that help us figure out which method to use.

Hopefully that helps some of you budget how long things will take

tk

ShortURL: http://www.toddklindt.com/MeasureCommand

Comments

Thanks for the tip!

This tip will come in handy as I am currently testing the upgrade/migration of Project Server 2007 to 2013. Now I will have a more accurate estimate of how long it will take.

Thanks again!
Brian Jones
 on 10/30/2013 5:00 PM

Re: Thanks for the tip!

I'm glad to hear you're testing your upgrade. I don't see enough of that. :)

tk
Todd O. KlindtNo presence information on 11/4/2013 10:15 PM

Great!

I've been using this command for quite some time. A really GREAT write-up!
 on 11/14/2013 12:41 PM

Re: Time Operations in PowerShell with Measure-Command

Measure, Manage, Improve Todd.  Love it!
 on 11/30/2013 10:41 AM

disneyplus.com/begin

I learned a lot from this article. Thanks for sharing your knowledge and expertise with us. It has been very helpful. <a href="https://disneyplusbegins.com/">disneyplus.com/begin</a>
 on 9/4/2024 6:28 AM

disneyplus.com login/begin

This was a fantastic read! Thank you for offering such practical advice. Your posts are always full of useful information. https://disneypluss-combegiin.com/
 on 9/13/2024 4:57 AM

www.kroger.com/feedback survey

"Thank you for sharing such a well-researched and detailed article. It was very enlightening."
<a href="https://wwwkrogerfeedbacksurvey.com/">www.kroger.com/feedback survey</a>
 on 9/14/2024 1:37 AM

kroger.com/feedback

"Your post was both engaging and informative. Thank you for delivering such valuable content."
https://wwwkrogerfeedbacksurvey.com/
 on 9/14/2024 1:38 AM

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Body *


Today's date *

Select a date from the calendar.
Please enter today's date so I know you are a real person

Twitter


Want a message when I reply to your comment? Put your Twitter handle here.

Attachments

 

 SysKit