Get Last boot of all servers in AD

I would like to share with you a powerful script which provides you Last reboot time and if the machine is available or not. Easily you can make “function Menu” and then filter it per OU or per operating system.


  • You have run it through Windows Server 2012 with RSAT or directly from DC
$Server = (get-ADcomputer  -filter {operatingsystem -like "Windows server*"}).name

$Running = "The server is Running."

foreach ($item in $Server)


          $TestCon = Test-Connection $item -Count 3 -ErrorAction SilentlyContinue

          if ($TestCon)


                   $BootTime = Get-WmiObject Win32_OperatingSystem -ComputerName $item -ErrorAction SilentlyContinue | select CSName, @{ LABEL = 'LastBootUpTime'; EXPRESSION = { $_.ConverttoDateTime($_.lastbootuptime) } }

                   Write-Host $item,$Running,Last boot is : $BootTime.LastBootUpTime -f black -b green




                   Write-Warning  "Sorry but $item isn't available for checking "



You can change the ‘”$Running’” variable to any text you want and the “-f’” color as well.

As you can see I am filtering the query by “Windows Server*” attribute in the same method you could change the like to: “Windows 7*” and then you might get all Windows 7 machines.

operatingsystem -like "Windows server*"

look at the result:

last boot servers powershell