title: Checking if windows security patches are installed on multiple servers
body: <p>I am trying to check if the specified KB # that I have set in my variables list matches the full list of KB installed patches on the server.  If it matches, it will display that the patch is installed, otherwise it will state that it is not installed.</p>
  
  <p>The code below does not seem to work, as it is showing as not installed, but in fact it's already been installed. </p>
  
  <pre><code>[CmdletBinding()]
  
  param ( [Parameter(Mandatory=$true)][string] $EnvRegion )
  
  if ($EnvRegion -eq "kofax"){
      [array]$Computers = "wprdkofx105", 
                          "wprdkofx106", 
                          "wprdkofx107", 
  
                $KBList = "KB4507448",
                          "KB4507457",
                          "KB4504418"
  }
  elseif ($EnvRegion -eq "citrix"){
      [array]$Computers = "wprdctxw124",
                          "wprdctxw125",
  
                $KBList = "KB4503276",
                          "KB4503290",
                          "KB4503259",
                          "KB4503308"
  }
  
  ### Checks LastBootUpTime for each server
  
  function uptime {
      gwmi win32_operatingsystem |  Select 
      @{LABEL='LastBootUpTime';EXPRESSION= 
      {$_.ConverttoDateTime($_.lastbootuptime)}} | ft -AutoSize
  }
  
  ### Main script starts here.  Loops through all servers to check if 
  ### hotfixes have been installed and server last reboot time
  
  foreach ($c in $Computers) {    
  Write-Host "Server $c" -ForegroundColor Cyan
  
  ### Checks KB Installed Patches for CSIRT to see if patches have been 
  ### installed on each server 
  
      foreach ($elem in $KBList) {
  
      $InstalledKBList = Get-Wmiobject -class Win32_QuickFixEngineering - 
      namespace "root\cimv2" | where-object{$_.HotFixID -eq $elem} | 
      select-object -Property HotFixID | Out-String
          if ($InstalledKBList -match $elem) {
              Write-Host "$elem is installed" -ForegroundColor Green
          } 
          else { 
              Write-Host "$elem is not installed" -ForegroundColor Red
          }
      }
      Write-Host "-------------------------------------------"
      Invoke-Command -ComputerName $c -ScriptBlock ${Function:uptime}
  }
  
  Read-Host -Prompt "Press any key to exit..."
  </code></pre>