Skip to content

Instantly share code, notes, and snippets.

@codereflection
Last active February 10, 2016 21:48
Show Gist options
  • Save codereflection/f84c7f99401d6b51d72a to your computer and use it in GitHub Desktop.
Save codereflection/f84c7f99401d6b51d72a to your computer and use it in GitHub Desktop.
$ServerName = $args[0]
if ($serverName -eq $Null) {
$serverName= $env:COMPUTERNAME
}
$timeVal = (Get-WmiObject -ComputerName $ServerName -Query "SELECT LastBootUpTime FROM Win32_OperatingSystem").LastBootUpTime
#$timeVal
$DbPoint = [char]58
$Years = $timeVal.substring(0,4)
$Months = $timeVal.substring(4,2)
$Days = $timeVal.substring(6,2)
$Hours = $timeVal.substring(8,2)
$Mins = $timeVal.substring(10,2)
$Secondes = $timeVal.substring(12,2)
$dayDiff = New-TimeSpan $(Get-Date -month $Months -day $Days -year $Years -hour $Hours -minute $Mins -Second $Secondes) $(Get-Date)
$Info = "" | select ServerName, Uptime
$Info.servername = $servername
$d =$dayDiff.days
$h =$dayDiff.hours
$m =$dayDiff.Minutes
$s = $daydiff.Seconds
$info.Uptime = "$d Days $h Hours $m Min $s Sec"
$Info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment