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