0

So I am trying to write a script to check remote machines to see if they have specific updates. It works when there is 1 entry in variable. However, It would be much better if I could check multiple variables and return a result for each variable. for example: a=x , b=y, c=w check for x & print result; check for y & print, check for w & print. also, don't know why but it seems to offset every variable name by 1 20h2=0h2, except derp.

set "20h2=KB4562830"
set "1809=KB1234567"
set "20H2-SEC=KB2456789"
set "DERP=Four"

set ^"RECENTS=%20h2%^

%1809%^

%20h2-sec%^

%DERP%^"



echo ++Looking for !RECENTS!

psexec -accepteula \\%COMPUTER% cmd /c powershell.exe -command "& {get-hotfix -computername localhost  | select InstalledOn,HotFixID,Description | Sort-Object -Descending -Property InstalledOn -ErrorAction SilentlyContinue |findstr !RECENTS!}
""
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Murpire
  • 1
  • 1
  • 2
    And don't start a variable name with a number. `%20h2%` is interpreted as "the value of the second parameter" (`%2`, probably empty) followed by the literal string `0h2`. The closing `%` is ignored (considered as an opening `%` but invalidated because there is no matching closing `%`) – Stephan Feb 06 '22 at 09:32
  • @Stephan, I am on my phone and cannot test. But does the `^` after `set` not cause an error? – Gerhard Feb 06 '22 at 09:59
  • (although I guess `findstr` can't handle the multi-line variable properly) – Stephan Feb 06 '22 at 10:57
  • @Stephan, `findstr` *can* search beyond line-breaks but they have to literally equal, hence carriage-return plus line-feed characters must be specified; but the whole multi-line string is then considered as a *single* search expression, so this is not suitable to find one out of a (multi-line) list; note that `findstr` just returns the first line of the match. The asker would need `findstr /G` here… – aschipfl Feb 06 '22 at 12:45
  • @aschipfl I know it can search over multiline. But what about the "linefeeds" in the searchstring? – Stephan Feb 06 '22 at 13:09
  • @Stephan, the won't match anything, assuming the command line left of the pipe outputs standard Windows line-breaks (CR + LF)… – aschipfl Feb 06 '22 at 14:08
  • @Stephan ok thank you I didn't know it would do that, I'll just work around with another name then. – Murpire Feb 07 '22 at 22:39
  • @aschipfl is there an argument that would be better fitted to assembly line like input? Or is there a way to structure a command so that it loops to check through multiple arguments? I would like it to check for and print all of the arguments. – Murpire Feb 07 '22 at 22:44
  • `for %%a in (alpha beta gamma delta) do echo %%a` – Stephan Feb 08 '22 at 08:49
  • @Stephan Thanks, that worked. – Murpire Feb 16 '22 at 20:38

0 Answers0