Created
February 25, 2013 03:01
-
-
Save PowerSchill-xx/5027172 to your computer and use it in GitHub Desktop.
PowerShell: Get-SystemUptime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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