0

I wrote a batch file to provide folder(D:\Test) access to list of user present in a txt(D:\users) file . Now I want a log file(D:\log) having names of who were provided access.

Here is my code:

FOR /F "delims=" %%A in (D:\users.txt) DO icacls "D:\Test" /grant %%A:(OI)(CI)F /T > D:\log.txt

Output in log file:

Successfully processed 0 files; Failed processing 1 files

But I want those names who were given access.

Note:- D:\users text file contains correct user names and incorrect user names also.

Abhishek kumar
  • 4,347
  • 8
  • 29
  • 44
  • `>>` appends to a file. See http://stackoverflow.com/questions/41030190/command-to-run-a-bat-file/41049135#41049135 – ACatInLove Feb 23 '18 at 07:13

1 Answers1

0

Assuming that your ICACLS command is correct I'd assume this would work:

For /F "UseBackQ Delims=" %%A In ("D:\users.txt"
) Do "D:\Test" /grant %%A:(OI)(CI)F /T>>"D:\log.txt"

and if you want the errors too I'd suggest:

For /F "UseBackQ Delims=" %%A In ("D:\users.txt"
) Do "D:\Test" /grant %%A:(OI)(CI)F /T>>"D:\log.txt" 2>>&1
Compo
  • 36,585
  • 5
  • 27
  • 39