Created
February 7, 2018 17:13
-
-
Save royashbrook/f583e20c3d6f93a9c73549ff44c0acdf to your computer and use it in GitHub Desktop.
This file contains 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-Uptime { | |
Param ( [string] $ComputerName = $env:COMPUTERNAME ) | |
$os = Get-WmiObject win32_operatingsystem -ComputerName $ComputerName -ErrorAction SilentlyContinue | |
if ($os.LastBootUpTime) { | |
$uptime = (Get-Date) - $os.ConvertToDateTime($os.LastBootUpTime) | |
Write-Output ("Last boot: " + $os.ConvertToDateTime($os.LastBootUpTime) ) | |
Write-Output ("Uptime : " + $uptime.Days + " Days " + $uptime.Hours + " Hours " + $uptime.Minutes + " Minutes" ) | |
} | |
else { | |
Write-Warning "Unable to connect to $computername" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment