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 }

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




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. :)

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


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

Re: Time Operations in PowerShell with Measure-Command

It's great to see your proactive approach to testing and timing tasks. Using Measure-Command in PowerShell is indeed a useful way to measure how long a command or script takes to execute. It's a valuable tool for estimating time and making informed decisions. Thank you for sharing this insightful article.
 on 12/20/2023 10:56 PM


Measure-Command is presented as a valuable tool for PowerShell users, offering a straightforward way to measure and analyze the execution time of scripts or script blocks, which can be crucial for planning and estimating time for various tasks
 on 1/18/2024 12:48 AM


Thank you for reaching out, Ruby. I appreciate your offer but currently I don't need any headphone accessories for the rice purity test team member. Have a good day!
 on 1/21/2024 12:12 AM

Re: Time Operations in PowerShell with Measure-Command

Risk management is an integral part of strategic planning for businesses, check more details It involves the identification, assessment, and mitigation of potential risks that could impact the organization. By proactively addressing uncertainties, risk management not only safeguards against potential threats but also enhances decision-making processes. A well-implemented risk management framework is essential for maintaining stability and promoting sustainable growth in dynamic and ever-changing environments.
 on 1/25/2024 4:45 PM

WhatsApp APK

<a href="">WhatsAppGold</a> has many features, which has made millions of people download and use it to enjoy its wonderful features. It is also completely safe for your phone and ensures complete privacy without compromising it.
 on 2/6/2024 11:29 AM

Weshape soul

Fitness Experts, Nutritionist, Diet Plans, Weight Loss, Health, Wellness, Weight Gain, Dietitian, Fitness, 15 Weight Loss Tips for People With Chronic Condition.
 on 3/24/2024 6:52 AM
1 - 10Next

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.


Body *

Today's date *

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


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