title: Powershell, How to get date of last Windows update install or at least checked for an update?
body: <p>I am trying to find a way of retrieving the date/time of which the last windows update was either installed, or checked for.</p>
  
  <p>So far I have found a function that allows to list recent Windows Updates, but it is far too much data and too bloated for such a simple function. Secondly I have tried to access the registry although I am having no luck in retriving the value I am after.</p>
  
  <p>I am testing this on a Windows 10 Machine although the software will probably reside on Windows Server 2012 R2.</p>
  
  <p>Here is an example of some of the code I have tried:</p>
  
  <pre><code>$key = “SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\Results\Install” 
  $keytype = [Microsoft.Win32.RegistryHive]::LocalMachine 
  $RemoteBase = [Microsoft.Win32.RegistryKey]::OpenBaseKey($keytype,"My Machine") 
  $regKey = $RemoteBase.OpenSubKey($key) 
  $KeyValue = $regkey.GetValue(”LastSuccessTime”) 
  
  $System = (Get-Date -Format "yyyy-MM-dd hh:mm:ss")  
  </code></pre>
  
  <p>Also, just trying the Get-ChildItem</p>
  
  <pre><code>$hello = Get-ChildItem -Path “hkcu:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\”
  
  foreach ($a in $hello) {
  
  $a
  
  }
  </code></pre>
  
  <p>I've checked in regedit and this key does not exist. Going to the "Windows Update" path shows only App Updates and not Windows updates.</p>
  
  <p>EDIT
  I seem to be closer to my goal with this line:
  Get-HotFix | Where {$_.InstallDate -gt 30}</p>
  
  <p>However how to I only retrive those of which have been installed in the last 30 days? And this doesnt show many results, even using <code>Select $_.InstallDate</code></p>