list the last install date and time for windows updates on servers

PowerShell
Edit|Remove
# This script shows the last time that a successfull Windows Update was installed.

cls
add-PSSnapin quest.activeroles.admanagement
$OnlineServers = @()

Get-QADComputer -SearchRoot 'domain.com/ServerOU'  -OSName "Windows*Server*" | %{
  
  $PingResult = Get-WmiObject -Query "SELECT * FROM win32_PingStatus WHERE address='$($_.Name)'"
  
  If ($PingResult.StatusCode -eq 0) 
  {
     # Add the current name to the array
    $OnlineServers += "$($_.Name)"
  }
}

foreach ($Server in $OnlineServers )
{
	
		$key = “SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\Results\Install”
		$keytype = [Microsoft.Win32.RegistryHive]::LocalMachine
		$RemoteBase = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($keytype,$Server)
		$regKey = $RemoteBase.OpenSubKey($key)
		$KeyValue = $regkey.GetValue(”LastSuccessTime”)
	
		$System = (Get-Date -Format "yyyy-MM-dd hh:mm:ss") 
			
		if	($KeyValue -lt $System)
		{
			Write-Host " "
			Write-Host $Server "Last time updates were installed was: " $KeyValue
		}
	}