How to list last patch

Hello, starting a new thread as maybe I need a new direction to solve this challenge

I need to create an analysis or report that list the server latest patch and the date it was installed, I don’t need a list of ALL the patches but just the last one.

I tried some of the suggestions in the forum but none of them list the actual patch just the date as below

thanks.

if (not Windows of operating system) then “N/A” else if (exists wmi) then (maximum of (it as date) of (((it as integer as string) of preceding text of last “/” of following text of first “/” of it ) &" “& (preceding text of first “/” of it as integer as month as three letters)&” "& (following text of last “/” of it as integer as string)) of (((string value of property “InstalledOn” of it) of select objects “InstalledOn from Win32_QuickFixEngineering” of wmi))) as string else (“N/A”

Being able to use PowerShell in Properties/Analyses would definitely have helped here, because this is very easy in PS:

(get-hotfix | sort installedon)[-1]
Source Description HotFixID InstalledBy InstalledOn


REDACTED Security Update KB4343909 NT AUTHORITY\SYSTEM 8/15/2018 12:00:00 AM

In order to get this from WMI you’d have to somehow compare the latest date and then pull the HotFixID select:

selects “HotFixID,InstalledOn from Win32_QuickFixEngineering” of wmis

No idea how to do that, unfortunately.

Thank you @mwolff, I wish I could do that, but no can do…I can get all the patches names and all the installation dates, but no the last one on its own (in the case below KB3202790…)

q: if (exists wmi) then ((string value of property “HotFixID” of it, string value of property “Description” of it, string value of property “InstalledOn” of it) of select objects “HotFixID, Description, InstalledOn from Win32_QuickFixEngineering” of wmi) as string else (“N/A”)
A: KB3199986, Update, 11/21/2016
A: KB3202790, Security Update, 8/14/2018
A: KB3200970, Security Update, 11/21/2016
T: 1725.670 ms

1 Like

I was able to pull the maximum date from InstalledOn and convert it back into the format in WMI:

Q: (month of it as integer as string & “/” & day_of_month of it as string & “/” & year of it as string) of (maximum of (it as date) of (((it as integer as string) of preceding text of last “/” of following text of first “/” of it ) &" “& (preceding text of first “/” of it as integer as month as three letters)&” "& (following text of last “/” of it as integer as string)) of (string values whose (it contains “/”) of selects “InstalledOn from Win32_QuickFixEngineering” of wmi))
A: 8/15/2018
T: 319.646 ms
I: singular string

I was thinking that this would let me parse the maximum installation date back into the WMI query, like so:

Q: string values of selects “HotFixID from Win32_QuickFixEngineering where InstalledOn=‘8/15/2018’” of wmi
A: KB4343902
A: KB4343909
T: 463.275 ms
I: plural string

Unfortunately, you have to substitute the relevance into a string, which then looks like this:

Q: string values of selects (“HotFixID from Win32_QuickFixEngineering where InstalledOn='” & (month of it as integer as string & “/” & day_of_month of it as string & “/” & year of it as string) of (maximum of (it as date) of (((it as integer as string) of preceding text of last “/” of following text of first “/” of it ) &" “& (preceding text of first “/” of it as integer as month as three letters)&” “& (following text of last “/” of it as integer as string)) of (string values whose (it contains “/”) of selects “InstalledOn from Win32_QuickFixEngineering” of wmi)) &”'") of wmi
A: KB4343902
A: KB4343909
T: 657.170 ms
I: plural string

This obviously has the potential of returning multiple values as in my case, since both KBs were installed on the same day, but it should in theory tell you which patches were last installed…

It’s pretty convoluted and I’m almost confident there has to be a better way; right now, this jumps through so many hoops of conversions it’s not even funny…

  1. Parse all InstalledOn values from Win32_QuickFixEngineering and convert them into a BigFix date format (Wed, 15 Aug 2018)
  2. Convert the maximum of the returned results back into a format that WMI recognizes (8/15/2018)
  3. Substitute the maximum date into a relevance string WMI filter to return the HotFixID(s) that matches the date filter

Definitely not elegant, but I believe it does return the data you are after… If anyone can come up with a more elegant solution I’m all for it!

@mwolff, fantastic help thank you very much at least we know that it can work using relevance even if as you say is complex and very convoluted which I don’t understand as like you say is quite easy in power shell and even in perl which is what I was trying as I was about to give up on the whole relevance thing…now, silly question but after doing all that…how do you get the console to show the correct result as
KB3202790, Security Update, 8/14/2018

Thanks again!!!

Q: (string values of properties “HotFixID” of it, string values of properties “Description” of it, string values of properties “InstalledOn” of it) of select objects (“* from Win32_QuickFixEngineering where InstalledOn='” & (month of it as integer as string & “/” & day_of_month of it as string & “/” & year of it as string) of (maximum of (it as date) of (((it as integer as string) of preceding text of last “/” of following text of first “/” of it ) &" “& (preceding text of first “/” of it as integer as month as three letters)&” “& (following text of last “/” of it as integer as string)) of (string values whose (it contains “/”) of selects “InstalledOn from Win32_QuickFixEngineering” of wmi)) &”'") of wmi
A: KB4343902, Security Update, 8/15/2018
A: KB4343909, Security Update, 8/15/2018
T: 637.705 ms
I: plural ( string, string, string )

1 Like

Hello @mwolff, I don’t know much about elegance, but man this is a great solution as it provides exactly what I need as the fact that if two patches are installed at the same day, then both must be listed!!!

Thanks/gracias/tack sa micket!!!

1 Like

Happy to help! Like I said, there’s probably a better way to do this as the proposed method iterates through a bunch of WMI calls, which is not recommended.

I would be careful with how often you pull this property as it could adversely affect performance. Also note that you will run into errors; I saw several WMI errors when running a one-time query against my environment using the above logic.

Thank you mwolff, I will try to use this one but let’s wait and see if someone has other ideas…

Hi @mwolff,

I need the thing but Its working on QNA, when I put this is my console its shows error.

Q:(string values of properties “HotFixID” of it, string values of properties “Description” of it, string values of properties “InstalledOn” of it) of select objects ("* from Win32_QuickFixEngineering where InstalledOn=’" & (month of it as integer as string & “/” & day_of_month of it as string & “/” & year of it as string) of (maximum of (it as date) of (((it as integer as string) of preceding text of last “/” of following text of first “/” of it ) &" “& (preceding text of first “/” of it as integer as month as three letters)&” “& (following text of last “/” of it as integer as string)) of (string values whose (it contains “/”) of selects “InstalledOn from Win32_QuickFixEngineering” of wmi)) &”’") of wmi
E: The expression could not be evaluated: Windows Error 0x80041017: Invalid query

Alas the web page formatting can change certain characters. Change the ` characters to ’

Q:(string values of properties "HotFixID" of it, string values of properties "Description" of it, string values of properties "InstalledOn" of it) of select objects ("* from Win32_QuickFixEngineering where InstalledOn='" & (month of it as integer as string & "/" & day_of_month of it as string & "/" & year of it as string) of (maximum of (it as date) of (((it as integer as string) of preceding text of last "/" of following text of first "/" of it ) &" "& (preceding text of first "/" of it as integer as month as three letters)&" "& (following text of last "/" of it as integer as string)) of (string values whose (it contains "/") of selects "InstalledOn from Win32_QuickFixEngineering" of wmi)) &"'") of wmi

2 Likes