PoshCode Archive  Artifact [94d202c84d]

Artifact 94d202c84dedc88321ac564d228e68555e2a15ce3c5633c6a3d431d933f30151:

  • File Get-SystemUptime.ps1 — part of check-in [0016326332] at 2018-06-10 13:47:08 on branch trunk — From gregs repository on github. (user: greg zakharov size: 888)

# encoding: ascii
# api: powershell
# title: Get-SystemUptime
# description: From greg’s repository on github.
# version: 0.1
# type: function
# author: greg zakharov
# license: CC0
# function: Get-SystemUptime
# x-poshcode-id: 4867
# x-archived: 2014-02-09T09:53:41
# x-published: 2014-02-03T13:50:00
#
#
#requires -version 2.0
function Get-SystemUptime([String]$Computer = '.') {
  <#
    .NOTES
        Author: greg zakharov
  #>
  
  try {
    New-TimeSpan ([Management.ManagementDateTimeConverter]::ToDateTime(
      ((New-Object Management.ManagementClass(
        [Management.ManagementPath]('\\' + $Computer + '\root\cimv2:Win32_OperatingSystem')
      )).PSBase.GetInstances() | select LastBootUpTime).LastBootUpTime
    )) (date) | ft -a
  }
  catch [Management.Automation.MethodInvocationException] {
    Write-Host Access denied. -fo Red
  }
}