Need to find if particular hotfix is installed or not

I have a list of servers on which i need to find a particular KB ex: KBXXXX is installed or not. Output file should tell me if KB is installed or not.

Also, some of the servers will not be reachable as WMI might not be working or they are offline, so script should right error message as "WMI is not working" or "server is offline" in the output file

Can someone help me with a powershell script?


Thanks
PS
P SAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

McKnifeCommented:
I'll give you an example script:

:: win8.1/server2012R2
ver |findstr /C:"6.3.9600" && reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\ApplicabilityEvaluationCache\Package_for_KB4025333~31bf3856ad364e35~amd64~~6.3.1.6" /v CurrentState |findstr 0x70 && goto end
:: server2012
ver | findstr /C:"6.2.9200" && reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\ApplicabilityEvaluationCache\Package_for_KB4025343~31bf3856ad364e35~amd64~~6.2.1.3" /v CurrentState |findstr 0x70 && goto end 
:: win7/server2008R2
ver | findstr /C:"6.1.7601" && wmic qfe get Hotfixid | findstr "4025341 4025337" && goto end
:: win10v1607/server2016
ver | findstr /C:"10.0.14393" && reg query "HKLM\software\microsoft\windows nt\currentversion" |findstr "0x5c8 0x5fc 0x639" && goto end
:: win10v1703
ver | findstr 15063 && reg query "HKLM\software\microsoft\windows nt\currentversion" |findstr "0x1e3 0x1f6 0x21c" && goto end
:: Server2008
ver | findstr /C:"6.0.6002" && wmic qfe get Hotfixid | findstr 4025409 && goto end
echo %date%>\\Someserver\logging$\!NotUp2date\%computername%.txt
:end

Open in new window


The strings in this script are for a particular patch - yours will be different and need to be changed.
P SAuthor Commented:
Thanks but I am looking for a powershell script for this.
McKnifeCommented:
And why would powershell serve you any better, if I may ask?
All the above commands work in powershell, too. It's just that && is not understood and would need to be exchanged for a powershell equivalent. But why care?

Let me tell you why I used batch: the powershell cmdlet get-hotfix did not work very well (didn't list updates as being installed, while in fact they were!), while the code above did. Don't use powershell for this.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

P SAuthor Commented:
I am new to powershell and trying to learn it. In my question, there could be 3 scenario's

1) WMI is working on the server but the patch is not installed

2) WMI is working but I don't have the access to query that server via WMI and in that case, I'll be getting "Access Denied" error

2) WMI is not working at all and I can't find the patch in that case

So i was wondering if someone could help me write a script as I am not sure if multiple condition can be applied in an "If" block.

I tried "Try" and "Catch" as well but it seems to be not working.

Thanks,
PS
McKnifeCommented:
Example syntax:
Get-HotFix -id KB3192137 -computername remoteserver | out-file \\server\loggingshare\remoteserver.txt

Open in new window

Output (if installed) would be
Source                Description      HotFixID             InstalledBy                           InstalledOn              
-------------                -----------             --------                  -----------                                  -----------              
remoteserver        Update           KB3192137     NT AUTHORITY\SYSTEM  9/12/2016 12:00:00 AM    

Output if not installed would be just an empty file (0 kB in size).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
McKnifeCommented:
Author abandoned the question. Suitable solution was demonstrated.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.