troubleshooting Question

Is there a way to set user permissions for a folder n directories deep without knowing the name of the folder?

Avatar of Skarley Guerrero
Skarley GuerreroFlag for United States of America asked on
Active Directory
5 Comments1 Solution106 ViewsLast Modified:
Hello,

I am writing a batch file to set user permissions for a plethora of folders. For one specific folder, I would like to set different permissions for each directory and sub-directory. The issue I'm having is getting to a certain level and setting permissions for all those folders. Example:

Main folder > (20 Folders in Main Folder) > (50 Folders in each sub-Main Folder) > (5 folders after that) > pdf files

The numbers are arbitrary, but that's somewhat how the construction of our file system looks like.

the directory right before the pdf files (5 folders after that) should have modify permissions. each sub-folder before that should have only folder creation permissions. Finally, the Main folder has read-only permissions.

What I have attempted so far is this batch script:

icacls "Main Folder" /grant:r %username%:M /T    

FOR /D %%S in ("Main Folder\*") do icacls "%%S" /grant:r Users:(R, AD) /grant:r %username%:(R, AD)

icacls "Main Folder" /grant:r Users:R /grant:r %username%:R



This sets the permissions I want but only up to this point:  Main folder > (20 Folders in Main Folder) > (50 Folders in each sub-Main Folder)

I've tried nesting a FOR loop to get into that last directory, but had no success.

Thank you!
ASKER CERTIFIED SOLUTION
Steve Knight
IT Consultancy

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros