Skip to content

Instantly share code, notes, and snippets.

@PowerSchill-xx
Created February 25, 2013 03:01
Show Gist options
  • Select an option

  • Save PowerSchill-xx/5027172 to your computer and use it in GitHub Desktop.

Select an option

Save PowerSchill-xx/5027172 to your computer and use it in GitHub Desktop.
PowerShell: Get-SystemUptime
function Get-SystemUptime ($computer = "$env:computername") {
$lastboot = [System.Management.ManagementDateTimeconverter]::ToDateTime("$((gwmi Win32_OperatingSystem -computername $computer).LastBootUpTime)")
$uptime = (Get-Date) - $lastboot
Write-Host "System Uptime for $computer is: " -NoNewline -ForegroundColor $ValueColor2
Write-Host $uptime.days -NoNewline -ForegroundColor $LabelColor
Write-Host " days " -NoNewline -ForegroundColor $ValueColor2
Write-Host $uptime.hours -NoNewline -ForegroundColor $LabelColor
Write-Host " hours " -NoNewline -ForegroundColor $ValueColor2
Write-Host $uptime.minutes -NoNewline -ForegroundColor $LabelColor
Write-Host " minutes " -NoNewline -ForegroundColor $ValueColor2
Write-Host $uptime.seconds -NoNewline -ForegroundColor $LabelColor
Write-Host " seconds" -ForegroundColor $ValueColor2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment