TransWikia.com

How can I find multiple values from windows command line output?

Server Fault Asked by MathewC on December 11, 2021

Example, to see if KB983590 is installed:

systeminfo | find "KB983590"

But what if I wanted to find out if more then one KB was installed?

4 Answers

You could also join multiple commands using &&

setlocal
set USERNAME=rbrown
net user %USERNAME% /domain | Find /i "Full Name" && net user %USERNAME% /domain | Find /i "Password expires"
endlocal

Full Name                    Richard Brown
Password expires             8/04/2021 9:32:54 am

Answered by user611474 on December 11, 2021

You can use a line like this:

FOR /F "usebackq tokens=5 delims= " %i IN (`netstat -ano ^|find "ESTABLISHED"`) DO @tasklist /fi "pid eq %i" | find "%i"

or, a bit shorter, this does the same:

netstat -a -b -n -o | findstr ESTABLISHED || tasklist | findstr PID

Answered by user12379030 on December 11, 2021

I'd go the route of 'find' instead of 'findstr' (simpler/easier)

systeminfo | find /I "kb"

you'll get your list.

use for /f to organize the data easier such as

for /f "tokens=2* delims= " %F IN ('systeminfo ^| find /I "kb"') DO ECHO %F%G%H

that will get rid of the numbered sequence from the beginning of each line.

if you want only the KB#####, change the tokens value to only 2 without the asterisk, and change the ending ECHO to just ECHO %F

for /f "tokens=2* delims= " %F IN ('systeminfo ^| find /I "kb"') DO ECHO %F%G%H>>"%USERPROFILE%desktopsysteminfo.txt"

will throw it on your desktop as a .TXT file

of course if you want it ina batch file, make sure your %F has an extra % (%%F)

Answered by Anthony Miller on December 11, 2021

Try this:

systeminfo | findstr "KB"

You can also use /i for case insensitive searching. Run findstr /? for even more options.

If you want to search for just a subset of patches, use spaces in between entries:

systeminfo | findstr "KB958488 KB976902 KB976932"

Answered by jftuga on December 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP