Examples/AnyRepo/Repo/Prod/OS/Get-Uptime.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
param(
      [string]$ComputerName
)

[hashtable]$computer_name = @{}

if ($ComputerName) {
      $computer_name.Add('ComputerName', $ComputerName)
}

Get-CimInstance @computer_name -ClassName Win32_OperatingSystem -Property LastBootUpTime -ea Stop |
    select @{Name='Uptime';Expression={[datetime]::Now.Subtract($_.LastBootUpTime)}} -First 1 |
        select -ExpandProperty Uptime