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.

NOTE:

  • 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

          }

          else

          {

                   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

About Meir Peleg 338 Articles
My name is Meir Peleg, (Born 30/04/1991) live in ISRAEL. Live and breath IT world. Microsoft MVP Windows IT & VMware vExpert.