Icacls Permissions help PLEASE

Hi guys, 

I have the below script that runs though folder and applies permissions to all folders, named "staff" and its content.

It does work, BUT until its gets to a folder with spaces in the name then it fails. I have thousands of folder names with spaces. Can someone please help me tweak this code to make it work?

This is my code, thank you very much.

for /F %i in ('dir F:\CurrentClients\*staff* /s /b /ad') do icacls %i /grant "SG-staff":(OI)(CI)(RX,W,AD,WA,WEA,REA) /inheritance:r

__________________________________________________________________

When doing a dir this is the output, it does pick up the correct folder:


C:\Users\testpc>dir C:\CurrentClients\*staff* /s /b /ad
C:\CurrentClients\Client 3\staff
C:\CurrentClients\Client1\staff
C:\CurrentClients\Client2\staff


C:\Users\testpc>for /F %i in ('dir C:\CurrentClients\*staff* /s /b /ad')
do icacls %i /grant "domain\username":(OI)(CI)(RX,W,AD,WA,WEA,REA) /inheritance:r

C:\Users\testpc>icacls C:\CurrentClients\Client /grant "domain\uername":(OI)(CI)(RX,W,AD,WA,WEA,REA) /inheritance:r
C:\CurrentClients\Client: The system cannot find the file specified.
Successfully processed 0 files; Failed processing 1 files

C:\Users\testpc>icacls C:\CurrentClients\Client1\staff /grant "domain\username":(OI)(CI)(RX,W,AD,WA,WEA,REA) /inheritance:r
processed file: C:\CurrentClients\Client1\staff
Successfully processed 1 files; Failed processing 0 files

C:\Users\testpc>icacls C:\CurrentClients\Client2\staff /grant "domain\username":(OI)(CI)(RX,W,AD,WA,WEA,REA) /inheritance:r
processed file: C:\CurrentClients\Client2\staff
Successfully processed 1 files; Failed processing 0 files

  • Edited by Lest3r Friday, July 31, 2015 9:42 AM updated
July 31st, 2015 7:47am

If this help anything, this is the dir:

C:\Users\testpc>dir C:\CurrentClients\*staff* /s /b /ad

C:\CurrentClients\Client 3\staff
C:\CurrentClients\Client1\staff
C:\CurrentClients\Client2\staff

The correct command would be

for /F "delims=" %i in ('dir C:\CurrentClients\*staff* /s /b /ad') do @echo %i

Free Windows Admin Tool Kit Click here and download it now
July 31st, 2015 1:04pm

Hi guys,

Thank you so much for the assistance. I have added "delims=" and its working beautifully :)

Have a great day! 

\_()_/

:P
  • Edited by Lest3r Monday, August 03, 2015 7:04 PM updated
August 3rd, 2015 7:04pm

I guys 

I have one more question please.

At the moment I have the flowing and I run them one by one:

for /F "delims=" %i in ('dir C:\CurrentClients\*staff* /s /b /ad') do icacls......

for /F "delims=" %i in ('dir C:\CurrentClients\*Stock* /s /b /ad') do icacls......

for /F "delims=" %i in ('dir C:\CurrentClients\*games* /s /b /ad') do icacls......

How do I use them as one? Because now I'd run the first script and wait 15 minutes for it to complete and go to the second etc.

Thank you 


  • Edited by Lest3r Sunday, August 09, 2015 9:00 AM updated
Free Windows Admin Tool Kit Click here and download it now
August 9th, 2015 8:06am

How do I use them as one? Because now I'd run the first script and wait 15 minutes for it to complete and go to the second etc.

You put them inside a batch file (and save yourself a lot of typing!):

@echo off
for /F "delims=" %%i in ('dir C:\CurrentClients\*staff* /s /b /ad') do icacls......
for /F "delims=" %%i in ('dir C:\CurrentClients\*Stock* /s /b /ad') do icacls......
for /F "delims=" %%i in ('dir C:\CurrentClients\*games* /s /b /ad') do icacls......

Remember to change every %i to %%i.

  • Marked as answer by Lest3r Sunday, August 09, 2015 8:37 PM
August 9th, 2015 10:20am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics