Get-UptimeDays
Get the localhost uptime, in days
Function Get-UptimeDays() { $lastBootUpTimeWMIObject = (Get-WmiObject -ComputerName $env:computername -Query 'SELECT LastBootUpTime FROM Win32_OperatingSystem') $lastBootUpDate = Get-Date ($lastBootUpTimeWMIObject.ConvertToDateTime($lastBootUpTimeWMIObject.LastBootUpTime)) $up = ((Get-Date) - (Get-Date $lastBootUpDate)).Days if ($up -lt "10") {Write-Host "Uptime: " -nonewline; Write-Host "only $up days" -ForegroundColor DarkMagenta} elseif ($up -gt "100") {Write-Host "Uptime: " -nonewline; Write-Host "more than $up days, so far..." -ForegroundColor DarkYellow} else {Write-Host "Uptime: " -nonewline; Write-Host "more than $up days, so far..." -ForegroundColor DarkMagenta} }