Here is an example of using Measure-Command to gather the execution time for loading the SQL Error log into a Out-GridView object:
1 2 3 4 5 |
# First, lets get the SQL Server object... $sqlServer = gi "SQLSERVER:\SQL\MySqlServer\Default" # That's all we needed to do. Let's get error log for any entries after the date listed and return to the Out-GridView object, and then output the measurement to the console. Measure-Command {$sqlServer.ReadErrorLog() | ? LogDate -gt '11/24/2014' | Out-GridView} | Out-Host |
which displays:
1 2 3 4 5 6 7 8 9 10 11 |
Days : 0 Hours : 0 Minutes : 4 Seconds : 5 Milliseconds : 104 Ticks : 2451043348 TotalDays : 0.00283685572685185 TotalHours : 0.0680845374444444 TotalMinutes : 4.08507224666667 TotalSeconds : 245.1043348 TotalMilliseconds : 245104.3348 |
An even better way, since using Measure-Command with prohibit output to Write-Host is to use a .Net timer. Her’s how to implement that:
1 2 3 4 5 6 |
$profileLoadTimer = [Diagnostics.Stopwatch]::StartNew() #add your code you want to measure but will also send output to the console $profileLoadTimer.Stop() Write-Host 'PowerShell Environment Load time: '$profileLoadTimer.Elapsed |
Views – 1744