# 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
}
}