Function Get-Uptime { Param([stringt]$computername=$env:computername) $os=Get-WmiObject win32_operatingsystem -computername $computername -ea SilentlyContinue if ($os.lastbootuptime) { Write-Host ("Last boot: {0}" -f $os.ConvertToDateTime($os.lastbootuptime)) Write-Host ("Uptime : {0}" -f ((get-date) - $os.ConvertToDateTime($os.lastbootuptime)).tostring()) } } Get-Uptime