Uptime

Uptime

A small PowerShell script to check the uptime of a computer over the network.

$ComputerName = "MACHINENAME"

$userSystem = Get-WmiObject win32_operatingsystem -ComputerName $ComputerName -ErrorAction SilentlyContinue 

if ($userSystem.LastBootUpTime) { 
$sysuptime= (Get-Date) - $userSystem.ConvertToDateTime($userSystem.LastBootUpTime) Write-Output ("Last boot: " + $userSystem.ConvertToDateTime($userSystem.LastBootUpTime) ) Write-Output ("Uptime : " + $sysuptime.Days + " Days " + $sysuptime.Hours + " Hours " + $sysuptime.Minutes + " Minutes" ) 
}
else { 
Write-Warning "Unable to connect to $computername" 
}

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.