1

I found this post with regard to getting a list of installed Hotfixes using wmic qfe list full and @Hackoo replied with the following:

@echo off
Title wmic to get HotfixID
Setlocal EnableDelayedExpansion
echo "patches" : {
set "patches=wmic qfe get HotfixID"
for /f "skip=1" %%i in ('%patches%') do for /f "delims=" %%j in ("%%i") do (
    set /a count=count+1
    echo "!count!" : "%%j",
)
echo }

This works absolutely fine but is it also possible to incorporate the Description and InstalledOn wmic information as well so that the output displays the following:

HotfixID InstalledOn Description

Using the above code I can get each individually but not all together as the InstalledOn / Description seem to repeat the first value.

I then stepped right outside my level of knowledge and tried the following (which does not work):

for /f "tokens=1,2,3 skip=1 delims=," %%a in ('%SystemRoot%\System32\wbem\wmic.exe qfe get HotfixID,InstalledOn,Description') do (
    set "hotfix_number=%%~a"
    set "hotfix_installed=%%~b"
    set "hotfix_description=%%~c"
)
echo %hotfix_number% installed on %hotfix_installed% - %hotfix_description%

Here's hoping you are able to assist.

Bri
  • 59
  • 6

1 Answers1

1

Does this help?

@For /F "Skip=2 Tokens=1,* Delims=," %%G In ('%SystemRoot%\System32\wbem\WMIC.exe QFE Get Description^, HotFixID^, InstalledOn /Format:CSV 2^>NUL') Do @For /F "Tokens=1-3 Delims=," %%I In ("%%H") Do @Echo %%J installed on %%K - %%I
Compo
  • 36,585
  • 5
  • 27
  • 39
  • Absolutely! Thank you. I thought I could maybe get the Description, InstalledOn and HotfixID by defining 3x tokens for each variable so my approach was at least correct (lol). Thank you very much. – Bri Jan 02 '22 at 13:11
  • Would you mind explaining what the `2^>nul` part is for and why you seem to escape chars with the caret symbol "`^`" that seemingly do not need to be escaped? – Bri Jan 02 '22 at 19:43
  • Run the code without the caret's, `^`, and tell me that those commas, `,` and/or redirection , `>`, characters don't need escaping! Then use your preferred research method to learn what `1>`, `2>` and `NUL` are, then try to work it out yourself, instead of just aking. – Compo Jan 02 '22 at 22:03
  • Well as far as I can tell `2>nul` is just the same as `>nul`. As for the escape chars in front of the commas, I only asked as I have never seen a wmic command that has used them when getting multiple values which is why I asked.. – Bri Jan 03 '22 at 20:17
  • It is not the same as `>nul` which is shorthand for `1>nul`. Please open your preferred search engine, and search for the term, `+"2>NUL"`. – Compo Jan 03 '22 at 22:02
  • Correct me if I am wrong here but in the past I’ve seen mods pull answers to peoples questions apart for just posting a code answer without any explanation of what is actually happening. With the above in mind I’d like to ask you again to explain your code as per the ‘supposed’ best practices of SO. Thanks – Bri Jan 04 '22 at 23:57
  • Never mind as ironically, my ‘preferred search engine’ directed me back to SO where it seems @Jeb had the patience and humility to actually provide an answer to another user who also did not understand the aforementioned command: https://stackoverflow.com/a/19599228/16939024 – Bri Jan 05 '22 at 00:05
  • @Bri, you are supposed to have the patience to use the site search facility, and your chosen search engine/reference materials to find answers for yourself, before expecting others to just give them to you. I'm sorry if you think that I'm at fault here, but just because I've provided you with an answer to your submitted question, I should not be expected to take on the role of your personal support service, without any indication that you've first of all attempted to help yourself. – Compo Jan 05 '22 at 00:27