get-uptime.ps1
<#PSScriptInfo
.VERSION 1.1 .GUID 4da9bf7e-728c-47a6-bd76-b845f951a64f .AUTHOR Max Knor .COMPANYNAME Microsoft .COPYRIGHT (c) 2016, Max Knor .TAGS uptime .LICENSEURI https://opensource.org/licenses/MIT .PROJECTURI .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES #> <# .DESCRIPTION Get the uptime of the current machine. #> [CmdletBinding()] Param() $lastboottime = (Get-CimInstance -ClassName win32_operatingsystem).LastBootUpTime $uptime = (Get-Date) - $lastboottime $time = Get-Date -Format "T" Write-Host " $time up" $uptime.days "days," $uptime.hours "hours," $uptime.minutes "minutes," $uptime.seconds "seconds" |