Recursively add permissions to a users home folder with icacls


Having issues with long file paths also when trying to set permissions? Check out this guide on how to find long paths and correct them.

First you’re most likely going to need to take ownership of the data before you will be able to set the perms, my preferred method is to use takeown.

takeown /F ROOT_FOLDER /A /R /D /Y

/F           filename        Specifies the filename or directory
                             name pattern. Wildcard "*" can be used
                             to specify the pattern. Allows

/A                           Gives ownership to the administrators
                             group instead of the current user.

/R                           Recurse: instructs tool to operate on
                             files in specified directory and all

/D           prompt          Default answer used when the current user
                             does not have the "list folder" permission
                             on a directory.  This occurs while operating
                             recursively (/R) on sub-directories. Valid
                             values "Y" to take ownership or "N" to skip.

Once you have taken control you can then set the perms with the below.

icacls ROOT_FOLDER /grant DOMAIN\USER:F /t

To address all files even with longer path names use the below

So prefixing my path with the string “\\?\” as below, allows icacls to successfully address longer file paths.

iicacls \\?\ROOT_FOLDER /grant DOMAIN\USER:F /t

When my script runs using this prefix, it now runs correctly, and successfully processes all files without error….SUCCESS!!! NB this also works with UNC paths.

Found priceless insights in this blog? Support the author’s creativity – buy them a coffee!

1 thought on “Recursively add permissions to a users home folder with icacls

Leave a Reply

Your email address will not be published. Required fields are marked *