Powershell – Get last boot time of remote computers


Hi Everybody,

I am writing this post after a long gap between the articles due to the busy schedule that I am having and I have also been planning new things to get more information to you guys. So I want to start off by saying thank you to all you guys for being supportive and visiting the website.

So today we will see how to get the last boot time of remote computers using Powershell.

Let me tell you how I got the idea of writing this article, when I was working on an issue and I realised that the computer was not responding through the Remote Desktop and I was trying to restart the machine remotely, but was not sure if the commands were actually executing on the other end. So I decided to find what was the last time the computer was up which would give me some information.

Anyways moving on, let us see what we will be using to achieve this and how we can use this in our day to day activities if need arises.

There are two ways to get this information, first from Get-CimInstance which you can use if you are on Powershell 3.0 and above. The second way is using the WMI Objects if you are using Powershell 2.0.

Lets see the properties associated with both the cmdlets and which will help us get the desired output.

First let us see the Get-CimInstance using the Win32_OperatingSystem class. Type the below on the Powershell screen and look for the properties.

Get-CimInstance Win32_OperatingSystem | Get-Member

Powershell - Get last boot time of remote computers

I am using this on the local machine, so if we have to check a remote computer we need to specify the Computername parameter. Let us see the help file now.

Powershell - Get last boot time of remote computers

So the final command that we will be using as shown below:

Get-CimInstance -ClassName win32_OperatingSystem | select csname, lastbootuptime

The above will fetch the information related to the local computer and below on the remote computer.

Get-CimInstance -ClassName win32_operatingsystem -ComputerName ED-EX2K10-CAH | select csname, lastbootuptime

Powershell - Get last boot time of remote computers

Now let us see how to get this information using Get-WMIObject.

Powershell - Get last boot time of remote computers

If you notice, in the first example the output of LastBootupTime was showing a value which did not make sense to us. Hence, we have used ConverttoDateTime to make it human readable.

Now let us try combining both the machines and check.

Powershell - Get last boot time of remote computers

You can append any number of machines as you saw here. If you have huge list, you can also make a text file and apply a foreach loop and get the information.

I hope this was informative and thank you for reading!


About Author

I am Adil Arif, working as a Senior Technical Support Engineer at Rubrik as well as an independent blogger and founder of Enterprise Daddy. In my current role, I am supporting infrastructure related to Windows and VMware datacenters.


    • Hi Prateek,
      CIM Classes are the parent classes on which WMI classes are built. To Manage the Windows infrastructure both CIM and WMI classes are necessary. CIM Classes got introduced in PowerShell 3.0, which leverages WS-Man protocol instead of native DCOM protocol used by WMI. You can google for more deeper information.

          • Dear Adil,
            Can u please elaborate how can I use foreach loop for multiple system which names are stored in a file (e.g. c:\systems.txt).

          • Hi Rajat,

            It should be pretty simple. Just assign the contents of the text file to a variable. Something like the below.

            $Servers = Get-Content C:\systems.txt
            foreach ($Server in $Servers){
            Get-CimInstance -ClassName win32_operatingsystem -ComputerName $Server | select csname, lastbootuptime

            Hope this helps.

  1. Wobblefishdisco on

    Hi Adil. Just a comment to say ‘nice site’ and to keep the articles coming 🙂

    All the best.

  2. Really helpfull. just wanted to know the script for checking if we can RDP the server. as there are multiple servers to check on.

      • Hi,

        I hope you can help me?

        I have a CSV file with 2 columns, “ServerName” & “Description”. I want to do a foreach lookup on the server name and find the last reboot time for each server, however, I also want to output the “Description” column so it looks like this

        ServerName Description LastRebootTime
        SVWQQQQQ, Mailxtender 01/01/2016 08:00:00
        SVWPPPPPP Mailxtender 01/01/2016 08:00:00
        SVWRRRRRR Mailxtender 01/01/2016 08:00:00

        Also, I want it to sort on last reboot time, if possible. Thanks

        CSV FILE Contents
        ServerName, Description
        SVWXXXXX,Enterprise Vault
        SVWTTTTT,Enterprise Vault
        SVWYYYYY,Enterprise Vault
        SVWIIIIIIIIIIII,Enterprise Vault

        • Hi Raks,

          Use the below.

          Import-Csv C:\Servers.csv
          $Output = foreach($Server in $Servers){
          Get-CimInstance $Server.ServerName | select csname,lastBootupTime | Sort-Object -Property lastBootupTime
          $Output | Export-Csv C:\Result.csv -NoTypeInformation

          Unfortunately, you can have to manually add the description field to the new file.

  3. Just a note. The script does not work for me. Something to do with the date conversion. If I just put the lastbootuptime I get the ugly thing (which is readable) but if I tack on convertodatetime it comes up blank. Not sure what the issue is.

Leave A Reply