Find a string in all files on all logical drives and log them

(imported topic written by tigger0191)

Hello,

I’m trying to search all files on all logical drives on all of our winodws servers for the string “i1pvs”. Here’s what I’ve tried:

dos echo Inventory of %COMPUTERNAME% > C:\NAScheck.txt

dos for /R c:\ %%i IN (*) do findstr /i /m /p “i1pvs” %%i >> C:\NAScheck.txt

dos for /R d:\ %%i IN (*) do findstr /i /m /p “i1pvs” %%i >> C:\NAScheck.txt

dos for /R e:\ %%i IN (*) do findstr /i /m /p “i1pvs” %%i >> C:\NAScheck.txt

dos for /R f:\ %%i IN (*) do findstr /i /m /p “i1pvs” %%i >> C:\NAScheck.txt

This runs each command one after the other without waiting for the last to complete. I’ve tried this with a wait in front of each line, but that errors on the first line and exits. I’m doing this in a task.

How can I make this work?

(imported comment written by labuski91)

easiest way is to write a batch file. or you could do wait cmd.exe /C “your command”

(imported comment written by tigger0191)

Thanks for the input. I couldn’t get the wait to work. I have had success with using appendfile commands to build a batch file on the endpoint and then run it. This works:

// Remove any prior attempts

delete “{(pathname of client folder of current site) & “\scanfiles.cmd”}”

delete C:\NAScheck.txt

// Create the batch file

appendfile @echo off

appendfile echo Inventory of %COMPUTERNAME% > C:\NAScheck.txt

appendfile for /R c:\ %%i IN (*) do findstr /i /m /p “i1pvs” “%%i” >> C:\NAScheck.txt

appendfile for /R d:\ %%i IN (*) do findstr /i /m /p “i1pvs” %%i >> C:\NAScheck.txt

appendfile for /R e:\ %%i IN (*) do findstr /i /m /p “i1pvs” %%i >> C:\NAScheck.txt

appendfile for /R f:\ %%i IN (*) do findstr /i /m /p “i1pvs” %%i >> C:\NAScheck.txt

// batch file was created as __appendfile

// move it to a batch file name

move __appendfile scanfiles.cmd

// now run it

run scanfiles.cmd

However, the line delete “{(pathname of client folder of current site) & “\scanfiles.cmd”}” produces the following error:

Command failed (File not found) delete “D:\Program Files\BigFix Enterprise\BES Client__BESData\CustomSite_FRB_MPLS_Content\scanfiles.cmd” (fixlet 114387)

I’ve verified that the file exists in the path above. Any idea why it would be “not found”? It’s really just a point of curiosity as, on successive runs, the move statement appears to overwrite scanfiles.cmd.

(imported comment written by BenKus)

It is OK to ignore the error from a delete command…

Note that the file only exists after the action runs (it won’t exist when the delete command executes)… and every time the site gathers, it will clear out all these temp files…

Ben