Use Powershell to check if Windows Update patch is installed

Here is a powershell function to check if a windows update patch is installed or not. It will return $True if it is installed and $False if it is not installed.

function Check-IsPatchInstalled {
	#√ėyvind Nilsen, oyvindnilsen.com
	PARAM (
       [Parameter(Mandatory=$false,ValueFromPipeline=$false)][String]$computer = "127.0.0.1",
       [Parameter(Mandatory=$true,ValueFromPipeline=$false)][String]$id
	)

    $patches = Get-WmiObject -Class Win32_QuickFixEngineering -ComputerName $computer | select description,hotfixid,installedon

    if ($patches | ? { $_.Hotfixid -like $id }) {
        return $true
    } else {
        return $false
    }
}

#Example 1, check if patch KB982018 is installed on the local computer.
Check-IsPatchInstalled -id "KB982018"

#Example 2, check if patch KB982018 is installed on a computer named Client01.
Check-IsPatchInstalled -compuer "Client01" -id "KB982018"

 

 

This entry was posted in Scripting and tagged , , , , , , , , , , , , . Bookmark the permalink.

One Response to Use Powershell to check if Windows Update patch is installed

  1. Anton says:

    Thank You very much!! Using this in SCCM 2012 as a Detection Method, with a minor change, for certain updates.

Leave a Reply

Your email address will not be published. Required fields are marked *