PoshCode Archive  Artifact Content

Artifact e7bc743b79a3ba68ed3532912d14c6363eb9f8e883ed47b332fbf6dd196a4bbf:

  • File uptime-cmd.ps1 — part of check-in [ed873d49d3] at 2018-06-10 13:55:04 on branch trunk — without wmi (user: greg zakharov size: 1197)

# encoding: ascii
# api: powershell
# title: uptime.cmd
# description: without wmi
# version: 0.1
# author: greg zakharov
# license: CC0
# x-poshcode-id: 5417
# x-derived-from-id: 5420
# x-archived: 2014-09-17T06:38:30
# x-published: 2014-09-10T14:39:00
#
#
rem #####################################################################
rem
rem Check system uptime with performance counter.
rem
rem PowerShell way:
rem $pc = New-Object Disgnostics.PerformanceCounter("System", "System Up Time", $true)
rem [void]$pc.NextValue()
rem [TimeSpan]::FromSeconds($pc.NextValue()) | select Days, Hours, Minutes | ft -a
rem
rem It's time to get same with usual batch file :)
rem
rem #####################################################################
@echo off
  setlocal
    for /f "tokens=2 delims=," %%i in (
      'typeperf "\System\System Up Time" -sc 1 ^| findstr /rc:"\:"'
    ) do set "sec=%%i"
    set "sec=%sec:"=%"
    for /f "tokens=1 delims=." %%i in ("%sec%") do set "sec=%%i"
    set /a "min=%sec% / 60"
    set /a "hor=%min% / 60"
    set /a "day=%hor% / 24"
    echo.Days    : %day%
    echo.Hours   : %hor%
    echo.Minutes : %min%
  endlocal
exit /b