Trouble changing date format in WMI query

Hello!

Case:
Retrieving the last date windows was patched to identify edge cases where for some reason windows havent been patched.

I have a script that works for that now:
following text of last "," of concatenation "," of concatenation "," of (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

The format right now is Month/Day_of_month/year

I cant manage to wrap my head around how to change the output of the query to year/month/day_of_month

If i change it to :

following text of last “,” of concatenation “,” of concatenation “,” of (string values of properties “InstalledOn” of it) of select objects ("* from Win32_QuickFixEngineering where InstalledOn=’" & (year of it as string & “/” & month of it as integer as string & “/” & day_of_month 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

It fails as refers to non existant object, because i am changing the wrong part im guessing and the it doesnt exist in WMI the way im querying it.

You’ve gone down a rabbit hole here.

Part of your relevance returns you a date, but not in the format you want:

(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))

You just need to take the value returned (which is a singluar date), extract the bits you want and put them back together

(year of it as string & "/" & month of it as two digits as string & "/" & day_of_month of it as two digits 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))

3 Likes

Thank you so much for saving my sanity, and your very correct.
I was too deep in the rabbithole to see how wrongly i built the query begin with.

Thank you! :star_struck:
Have a great weekend!