When was that box last restarted? When was that box last restarted?

When was that box last restarted?

When was that box last restarted?There’s a running joke on the Internet about how frequently Windows computers need reboots. For better or worse, proprietary enterprise software can sometimes fuel this joke as many in-house enterprise applications are developed with more of time-to-market and feature-rich goals instead of being robust and helping with the overall system stability for an individual server or workstation. As we all know, it’s cheaper to setup a job to reboot a workstation daily than to pay a developer to track down elusive memory issues or general application state issues.

With that in mind, with a little bit of Windows command line knowledge and using the PsExec component of the PsTools suite, you can very quickly and easily answer the question, “When was that box last restarted?”

Prerequisites

First, you’ll need to download PsExec. You can get this in the PsTools suite from TechNet:

After you download the PsTools zip file, you’ll need to find a home for it on your machine. Typically, we recommend to just create the folder “C:\PsTools” and unpack all of the files in the PsTools zip to your local “C:\PsTools” directory on your computer.

Download PsTools

Side note: it can be incredibly handy to have the PsTools package on every Windows computer on your network. We recommend you make it part of your standard Windows workstation and server build process to include a C:\PsTools directory with all the PsTools suite in it. For extra credit, use setx in your workstation and server build process to add C:\PsTools to the system’s PATH environment variable on every machine to make it even easier to use PsTools. Then you won’t have to fully qualify the path to your PsTools every time you want to use them (i.e. type “psexec” instead of “C:\PsTools\psexec”).

Run it!

What we’re really doing is taking advantage of Windows’ “net stats srv” command. If you run “net stats srv” (no quotes) on a Windows computer, the second line “Statistics since” shows you the date and time the computer was last started. If you combine this command with PsExec, you have a quick one-off command line way of seeing the date/time a Windows computer was last started. This can save you a lot of time due to ambiguity (“I think it was last rebooted on…”) and due to sifting through Event Viewer logs looking for that pesky “The operating system started …” message from Kernel-General.

Now that you have PsTools unpacked to C:\PsTools (or wherever you decided to put them), simply open up a command prompt and run:

C:\PsTools\psexec \\SERVER-A net stats srv

Where SERVER-A is the name of the computer on your network you want to check.

There's the time it was last rebooted

Of course this depends on you having permissions on SERVER-A. If you’re running this against a computer that is not on your domain, you can use PsExec’s -u and -p options to specify a username and password. Run “C:\PsTools\psexec -?” for more details about PsExec’s command line options.

As usual with Windows, there’s more than one way to do it, but combining PsExec and “net stats srv” is quick and requires no scripting/programming experience. How else do you find out your systems’ uptimes? Let us know in the comments below!

  1. you could also do these as scripts, but I have them load as functions in my powershell profile:

    function GLOBAL:boottime([String]$computer=”localhost”) {
    $wmiOsInformation = Get-WmiObject -computer $computer -class Win32_OperatingSystem
    $wmiOsInformation.ConvertToDateTime($wmiOsInformation.LastBootUpTime)
    }

    function GLOBAL:uptime([String]$computer=”localhost”) {
    $wmiPerfOsSystem = Get-WmiObject -computer $computer -class Win32_PerfFormattedData_PerfOS_System
    [TimeSpan] $systemUptime = New-TimeSpan -seconds $wmiPerfOsSystem.SystemUpTIme
    return [String]::Format(“{0:G}”, $systemUptime)

    }

Leave a Reply

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