Measuring Reboot Time with PowerShell

by Dan Franciscus Posted on September 03, 2019

In enterprise environments, you will usually find an array of different Windows operating systems, hardware and of course software. Typically, machines are managed and configured with group policy and SCCM, or perhaps other more modern methods like Chef or Puppet. One of the symptoms of an unhealthy Windows computer is the amount of time it takes to boot up.

Longer boot times can mean hardware is failing, such as slow hard disks. Or perhaps, there is a group policy that is holding up the process of getting to the login screen. In this article, I will show how you can use PowerShell to measure the number of seconds a computer(s) takes to go from shutting down and starting up.

Measure-RebootTime Command

A while back, we had a fleet of machines that users were complaining about. The issue was that certain machines were taking a long time to reboot, some even 15 minutes. Since these machines are not used at certain hours or days, I decided to create a PowerShell function to reboot a bunch and measure their reboot time. That is why I created Measure-RebootTime that includes a helper function Get-RebootTime.

The Get-RebootTime function itself is very simple. It used Measure-Command to measure using Restart-Computer while also waiting for PowerShell (WMI) to be available for remote connection. I also set a timeout of 1200 seconds. I then round the seconds to two decimals and throw it into a PSCustomObject.

$Time = Measure-Command {

    Restart-Computer -ComputerName $ComputerName -Wait -For powershell -Timeout 1200 -ErrorAction Stop

} | Select-Object -ExpandProperty TotalSeconds

$RoundedTime = [math]::Round($Time,2)

[PSCustomObject]@{

    ComputerName = $ComputerName

    Seconds = $RoundedTime

}

After creating Get-RebootTime I realized I wanted to make this process multiple computers at once, so I added Measure-RebootTime which uses PoshRSJob to process multiple machines in jobs. PoshRSJob is a great PowerShell community module written by Bo Prox that is widely used for utilizing PowerShell run spaces.

#requires -modules PoshRSJob

function Measure-RebootTime {

    [CmdletBinding()]

    param(

        [Parameter(Mandatory=$true)]

        [string[]]$ComputerName

    )

    $ComputerName | Start-RSJob -ScriptBlock {Get-RebootTime -ComputerName $_ } -Throttle 150 | Wait-RSJob | Get-RSJob | Receive-RSJob | Select-Object *

}
 

Testing It Out

So, in this example, I have two machines, Test-1 and Test-2 that I want to measure the seconds it takes to reboot them. I can simply add them both to the -ComputerName parameter in Measure-RebootTime.

C:\> Measure-RebootTime -ComputerName Test-1,Test-2




ComputerName Seconds

------------ -------

Test-1       51

Test-2       50




As we see, the returned object includes the computer name, and seconds it took to reboot the machine and have WMI accessible over the network. Of course, it is up the user to figure out how much time is acceptable for a reboot operation of a particular machine; in this case, it took about 50 seconds for each.

Summary

The real brains of these PowerShell functions are Measure-Command, Restart-Computer and Start-RSJob. All of which when combined can do this task very efficiently and easily with not much code or complexity involved. Using built-in PowerShell modules and community modules is something I have incorporated into my scripts, which has saved me a lot of time when writing functions.

 

Dan Franciscus
Dan Franciscus is a systems engineer and VMware Certified Professional (VCP) specializing in VMware, PowerShell, and other Microsoft-based technologies. You can reach Dan at his blog (http://www.winsysblog.com/) or Twitter at @dan_franciscus.
More from the author

Related Tags

Related Articles

How to Search Windows Event Logs Across Hundreds of Servers
The Windows event logs are a great place to start when troubleshooting problems or investigating potential security breaches.
Using the New MOVEit 2018 REST API with PowerShell
Logging into MOVEit's console or web interface works great for day-to-day management tasks or setting up one-time workflows but there are times when we need to automate with MOVEit Automation!
The PowerShell Script Orchestrator
With companies moving services to the cloud, applications offering robust APIs and a driving need for automation, we need a more mature scripting language.
Prefooter Dots
Subscribe Icon

Latest Stories in Your Inbox

Subscribe to get all the news, info and tutorials you need to build better business apps and sites

Loading animation