functions/Get-RebootTime.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<#
.SYNOPSIS
    Measure Bootup time remotely by rebooting machine and waiting for connectivity through WMI
#>

function Measure-RebootTime {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory=$true)]
        [string]$ComputerName
    )

    process {
        Try {
            $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
          }
        }
        catch {
            Write-Output "$ComputerName failed"
            $ErrorMessage = $_.Exception.Message
            $ErrorMessage
        }
    }
}