JSI Tip 8545. How can I generate a report of folders and files that have specific user or group permissions set?
Jerold Schulman
October 5, 2004
1 Min Read
I have scripted FindACL.bat to generate a comma separated value file that reports folders and files that have permissions for the users and groups that you specify.
FindACL.bat uses the built-in CACLS command, which displays users and groups in a format like:
BUILTINAdministratorsNT AUTHORITYSYSTEMUSERorGROUPEveryoneUSERorGROUP
The syntax for using FindACL.bat is:
FindACL Drive ReportFile UsrGrp1 [UsrGrp2 ... UserGrpN]
where:
Drive is the Drive Letter or folder path that contains the sub-folders and files.ReportFile is the file that will contain the output report.UsrGrpX is the users and/or groups you are looking for.
The format of the ReportFile file is:
"Fully Qualified Folder of File Name","User or Group"
NOTE: FindACL runs a long time, based upon the number of folders and files, and ACEs per file system object.
FindACL.bat contains:
@echo offif {%3}
{} @echo FindACL Drive ReportFile UsrGrp1 [UsrGrp2 ... UsrGrpN]&goto :EOFsetlocalset work=%1set work=%work:"=%#set drv=%work:#=%set drv=%drv:#=%set obj=%drv%if exist "%TEMP%FindACL.tmp" del /q "%TEMP%FindACL.tmp"set out=%2if exist %out% del /q %out%:loopif {%3}
{} goto fndset ACL=%3shiftset ACL=%ACL:"=%@echo %ACL%>>"%TEMP%FindACL.tmp"goto loop:fndcall :parsefor /f "Tokens=*" %%O in ('dir %drv% /b /s /a') do set obj=%%O&call :parsedel /q "%TEMP%FindACL.tmp" endlocalgoto :EOF:parsecall set remove=%obj:&= %set /a cnt = 0call echo.%%remove%%>%TEMP%$VarLen$.tmpfor %%n in (%TEMP%$VarLen$.tmp) do set /a cnt = %%~zn - 2set /a cnt=%cnt% + 1for /f "Tokens=*" %%f in ('cacls "%obj%"^|Findstr /i /l /g:"%TEMP%FindACL.tmp"') do ( set line=%%f call :strip)goto :EOF:stripif "%line%" EQU "" goto :EOFcall set line=%line:&= %call set line=%line:(={%call set line=%line:)=}%call set line=%line: = %call set work=%line:not found=%if "%work%" NEQ "%line%" goto :EOFif "%line:~1,1%" EQU ":" call set line=%%line:~%cnt%%%for /f "Tokens=1* Delims=:" %%a in ('@echo %line%') do ( set line=%%a )@echo "%remove%","%line%">>%out%
About the Author
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
You May Also Like