Check if a particular hotfix is already installed with PowerShell

PowerShell contains the get-hotfix cmdlet, which is an easy way to check if a given hotfix is installed on the local computer or a remote computer.

The example of the basic syntax is:

get-hotfix -id KB3134758

On my machine the command returns:

If the fix isn’t installed on your computer, an error will be returned:

To check a remote computer, add the -computername parameter.

For example:

get-hotfix -id KB4015438 -computername pc01-win10

If this hotfix is installed on your computer, this will produces the following output:

You can even add an action to perform if the fix isn’t installed, such as writing the computer name to a text file:

if (!(get-hotfix -id KB4015438 -computername pc01-win10)) {add-content $_ -path Missing-KB4015438.txt}

If you have a list of computer names, you can pass it to a command to check multiple machines. For example:

get-content computers.txt | foreach \{ if (!(get-hotfix -id KB4015438 -computername $_)) { add-content $_ -path Missing-KB4015438.txt } }

This will produces the following output:

Get-HotFix : This command cannot find hot-fix on the machine ‘pc01-win10’.
Verify the input and Run your command again.

Note: in the above error message that I received an error that the fix is missing from pc01-win10, because the computer or server is missing the update.

The computers.txt file has the following content:

pc01-win10
pc02-win10
pc03-win10
pc04-win10
pc05-win10

You can manipulate the commands to do any combination that you want, including checking for multiple hotfixes.

Download: Check Hotfix PowerShell script

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s