Retrieving acls from dir tree

I had a question answered a question for me on Experts Exchange by Sir Bounty ages OK and it works beautifuly. I wonder however if there is a way to modify it sligtly so that it only shows users with full control of a directory. The reason I ask is we have a share that power users have given standard users Full rights to a number of dir's where they shouldn't have and now I have to track them down :o(
I ran the string below and the file size produced is 55MB and it is too big for VBscript and Excel to work with.
Any help would be appreciated.
for /f %a in ('dir "C:\pro lib" /ad /b') do (for /r %a in (.) do cacls "%a") >> C:\CaclsReport.log

In summary; can this string be modified to produce a report that ONLY displays accounts with FULL access to dir?

Thanks in advance

Stuart
stubarAsked:
Who is Participating?
 
Steve KnightConnect With a Mentor IT ConsultancyCommented:
Exactly... if there are lots of groups it could get a bit long but you should be alright with a small selection:

@echo off
del c:\calcsreport.log 2>nul
for /f %a in ('dir "C:\pro lib" /ad /b') do (for /r %a in (.) do @cacls "%a" | findstr /E "F." | FIND /I /V "Administrators" | find /I /V "Everyone " | FIND /I /V "COMops") >> C:\CaclsReport.log

That could technically lose a line that has the word Everyone, COMops or Administrators in the directory / filename for instance though.... if that is a problem you can do a search for BUILTIN\Administrators etc. for instance


Steve

0
 
Steve KnightIT ConsultancyCommented:
Try this:

@echo off
del c:\calcsreport.log 2>nul
for /f %a in ('dir "C:\pro lib" /ad /b') do (for /r %a in (.) do @cacls "%a" | find "F*" | FIND /I /V "Administrators" | find /I /V "Everyone" ) >> C:\CaclsReport.log

That finds only lines with "F " in them which should (mainly at least) be those that end in F for full control.
It excludes lines that include Administrators or Everyone group by using the second two FIND commands.  Those can be removed if you wish..
Steve
0
 
Steve KnightIT ConsultancyCommented:
Sorry that F* should be F followed by a space:

@echo off
del c:\calcsreport.log 2>nul
for /f %a in ('dir "C:\pro lib" /ad /b') do (for /r %a in (.) do @cacls "%a" | find "F " | FIND /I /V "Administrators" | find /I /V "Everyone" ) >> C:\CaclsReport.log
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
Steve KnightIT ConsultancyCommented:
And actually if we use FINDSTR instead then we can make sure the F is on the end of the line in case you have any filenames containing an F and space after it... the F. means F followed by any character as findstr doesn't seem to like matching the space and the /E means the lines ends with these characters...

@echo off
del c:\calcsreport.log 2>nul
for /f %a in ('dir "C:\pro lib" /ad /b') do (for /r %a in (.) do @cacls "%a" | findstr /E "F." | FIND /I /V "Administrators" | find /I /V "Everyone" ) >> C:\CaclsReport.logback to top

Steve
0
 
stubarAuthor Commented:
Cheers Steve
That works :o)
If I wanted to add groups into the 'Please ignore this as well' would it be something like:
for /f %a in ('dir "C:\pro lib" /ad /b') do (for /r %a in (.) do @cacls "%a" | find "F*" | FIND /I /V "Administrators" | find /I /V "Everyone" | FIND /I /V "COMops" ) >> C:\CaclsReport.log

COMops is a group name which reads as (HC\COMops)

Cheers

Stuart
0
 
stubarAuthor Commented:
Absolutely spot on perfect, thank you.
And I appreciate the comments on helping to understand it as well.

Thanks

Stuart
0
 
stubarAuthor Commented:
Sorry Steve

I've just run this on the server, TS running 2000, and this is the error I'm getting:
find: unable to access "/I": The system cannot find the file specified.
find: unable to access "/V": The system cannot find the file specified.
find: unable to access "Everyone ": The system cannot find the file specified.
find: unable to access "/I": The system cannot find the file specified.
find: unable to access "/V": The system cannot find the file specified.
find: unable to access "Administrators": The system cannot find the file specified.

If you don't put in the exceptions it works EG | find /I /V "Everyone "

Any thoughts?

Cheers

Stuart
0
 
Steve KnightIT ConsultancyCommented:
Can you post exactly wht you are typing please.  I assume you are running it as a batch file?  You haven't called the batch file something like find.bat etc. have you?

Steve
0
 
stubarAuthor Commented:
Thanks for getting back so fast Steve

I created a 'Test 2' test folder and then ran it straight from the command line.
So, for the puposes of the command line I was in
E:\Test 2>for /f %a in ('dir "E:\Test 2" /ad /b') do (for /r %a in (.) do @cacls "%a" | find "F " | FIND /I /V "Administrators" | find /I /V "Everyone" ) >> C:\CaclsReport.log
0
 
stubarAuthor Commented:
I should also mention that when tested on an XP machine it worked firn and did as was expected

0
 
stubarAuthor Commented:
After advice I have also placed carets before the pipes but it still didn't work :o(

for /f %a in ('dir "C:\pro lib" /ad /b') do (for /r %a in (.) do @cacls "%a" ^| findstr /E "F." ^| FIND /I /V "Administrators" ^| find /I /V "Everyone " ^| FIND /I /V "COMops") >> C:\CaclsReport.log

Although the error changed. It now outputs to the log but instead of the results expected it is the standard help as if there was an error in the code.

Thanks again in advance

Stuart
0
 
Steve KnightIT ConsultancyCommented:
Busy right now, sorry.  I'll take a look later on.

I tested it on Windows 2000 and all seemed OK for me, I'll try your commandline out. You shouldn't ned the ^ characters before the pipes.

Steve
0
 
Steve KnightIT ConsultancyCommented:
Not available tomorrow, please remind me on Monday if this isn't sorted.

Steve
0
 
stubarAuthor Commented:
Thanks Steve, but don't worry about it.
Your line works fine everywhere else but where I actually need it, (typical!) so it's the box at fault not the code.

Thanks again for all your efforts and to everyone else as well.

Stuart
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.