PowerShell – Return Computer name, Count of Missing Updates, Missing KBs

email me

This will return missing patches (missing security and critical updates) based upon a KB text file. I used a fully patched computer + the published KBs from a patch server to create a master KBs.txt file. The KB file contains KBs by the numbers: KB11111, KB22222, etc (one per line). I also have a computers.txt file which permits you to query missing updates on multiple computers, remotely. Just to verify it was at least hitting the right ballpark number, I installed Belarc to crosscheck missing updates. So far, it has been 100% accurate.

The data comes out in CSV format (click image to zoom)

 

What you need

  • KBs.txt
  • Computers.txt
  • Admin access
  • The script I created below

 

Clear-Host

# Path to files
$filePath = "C:\scripts"

# the computers to check
$computerList = Get-Content -Path "$filePath\computers.txt" 

# the KBs to check
$patchList = Get-Content -Path "$filePath\KBs.txt" 

$E_Total = "" # exists total
$NE_Total = "" # not exists total
$Count = 0 # missing updates counter
$BoolCheck = 0 

 
foreach ($computer in $computerList)
{  
    
    # is machine online?
    $Ping = test-connection -ComputerName $computer -Count 2 -quiet 
 
    # yes, online
     if($Ping) 
        {         
       
        # get current list of hotfixes on machine
        $HotfixList = Get-HotFix -ComputerName $computer | select -Property "HotFixID"
 
        # cycle through each patch in list
        foreach($patch in $patchList)
        {         
            $BoolCheck=0
            
            
            # cycle through hotfixes on local machine
            foreach ($Hotfix in $HotfixList)                
            { 

                # compare local machine hotfixes with our list
                # if it matches, exists
                if ($patch -eq $Hotfix.HotFixID) 
                    {       
                        $BoolCheck=1                          
                        break
                      }             
                      
                       
                  }
               
               if ($found -eq 1) {
               $E_Total = "$E_Total,$patch"
               }
               
               if ($BoolCheck -eq 0) {
               # $patch
               $NE_Total = "$NE_Total,$patch"
               $Count=$Count+1
               }                
                   
            }
            # Write-Host "Found:   $Computer$E_Total"            
            Write-Host "$Computer,Missing $count$NE_Total"
            Write-Host " "
            
            # Clear session
            $E_Total = ""
            $NE_Total = ""
            $Count = 0
            $BoolCheck = 0
            
            
}
 
# no, not online
else 
{ 
Write-Host "$Computer,Not Online"
Write-Host " "
} 
}

 

The KBs in the KBs.txt file I used…though, yours will most likely be different due to imaging practices and new KB releases.

KB2305420
KB2393802
KB2479943
KB2491683
KB2506014
KB2506212
KB2506928
KB2509553
KB2511455
KB2515325
KB2533552
KB2536275
KB2536276
KB2538242
KB2544893
KB2545698
KB2547666
KB2552343
KB2560656
KB2563227
KB2564958
KB2565063
KB2570947
KB2574819
KB2579686
KB2584146
KB2585542
KB2592687
KB2603229
KB2604115
KB2619339
KB2620704
KB2621440
KB2631813
KB2640148
KB2644615
KB2647753
KB2654428
KB2660075
KB2661254
KB2667402
KB2670838
KB2676562
KB2685811
KB2685813
KB2685939
KB2690533
KB2698365
KB2705219
KB2709630
KB2709981
KB2712808
KB2718704
KB2719857
KB2726535
KB2727528
KB2729094
KB2732059
KB2732487
KB2732500
KB2736422
KB2742599
KB2750841
KB2761217
KB2763523
KB2770660
KB2773072
KB2786081
KB2791765
KB2799926
KB2803821
KB2807986
KB2808679
KB2813170
KB2813347
KB2813430
KB2820331
KB2832414
KB2834140
KB2835361
KB2839894
KB2840631
KB2841134
KB2843630
KB2846960
KB2847077
KB2847311
KB2847927
KB2849696
KB2849697
KB2852386
KB2853952
KB2861191
KB2861698
KB2861855
KB2862152
KB2862330
KB2862335
KB2862966
KB2862973
KB2864058
KB2864202
KB2868038
KB2868116
KB2868626
KB2872339
KB2884256
KB2887069
KB2888049
KB2891804
KB2892074
KB2893294
KB2893519
KB2900986
KB2910978
KB2911501
KB2912390
KB2913152
KB2913431
KB2918077
KB2919469
KB2920680
KB2929733
KB2929755
KB3072305
KB3085538
KB3085635
KB3087038
KB3101512
KB3114518
KB3115041
KB3115103
KB3115135
KB3115858
KB3122648
KB3124280
KB3126446
KB3127220
KB3127986
KB3178656
KB3178673
KB3178674
KB3210131
KB4012204
KB4012212
KB4013867
KB954430
KB958488
KB971033
KB976902
KB976932
KB982018