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
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.
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
Now let us see how to get this information using Get-WMIObject.
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.
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!