Bilal Ahmad
Bilal Ahmad

Reputation: 301

use for loop for psexec in same line

I have been banging my head with this small script to search a delete a file from the remote host. However, I have been able to write to seperate scripts, both to delete and to find a file.

However, now I am trying to merge both and I am unable to use the for loop in the same line as the line which searches the file.

Psexec @IPlist.txt -u ad -p P@$$vv0rCL cmd /c (^WHERE /r D:\ %file%>res.txt

the above line helps to search the file, and below does the deletion part.

del /f /A:H /S /Q "D:\1\e.txt"

Now, since I want to delete all the files, found and stored in rex.txt, I need to run a for loop on this file.

Here is what I am trying to do

Psexec @IPlist.txt -u ad -p P@$$vv0rCL cmd /c (^WHERE /r D:\ %file%>res.txt ^& FOR /f "delims=" %%X IN (res.txt) DO ( del /f /A:H /S /Q "D:\1\e.txt")

but this gives error cmd exit with error code 1, and if I take for loop on next line, then the code doesn't work on remote pc.

Can some one guide please?

Upvotes: 2

Views: 1146

Answers (1)

Magoo
Magoo

Reputation: 79982

escape the ) in (res.txt) as ^)

Upvotes: 1

Related Questions