Skip to content

Instantly share code, notes, and snippets.

@royashbrook
Created February 7, 2018 17:13
Show Gist options
  • Select an option

  • Save royashbrook/f583e20c3d6f93a9c73549ff44c0acdf to your computer and use it in GitHub Desktop.

Select an option

Save royashbrook/f583e20c3d6f93a9c73549ff44c0acdf to your computer and use it in GitHub Desktop.
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