ICACLS is another great command line tool but it can be a bit quirky, especially if you use the wrong character set.
My challenge was to copy the permissions from one folder to several other folders without using inheritance. I could have done this manually, but because I had to process hundreds of folders this would have taken several hours and I would have gotten a headache from clicking the same buttons over and over again.
So I decided to use ICACLS instead (this was on Windows Server 2008 R2).
Here is the Step-by-Step approach. NOTE: Make sure to use Unicode when you generate the ICACLS input file.
- Manually set the permissions on your folder that will serve as a template for all other folders. Example: E:\shared\template
- Run icacls with the /save option to save the permssions:
- icacls E:\shared\template /save template.txt
- now using Powershell get-childitem I retrieved the names of all of the folders that require the new permissions.
- Get-childitem -Path <pathname>|select-object Name
- I then copy the results of this command into a Text Editor. Example:
- Get-childitem -Path E:\Targetfolders|select-object Name
|
Folder 1 Folder 2 Folder 3 Folder 4 |
- Open the file template.txt generated in the step above and copy the line that looks similar to this into your Clipboard:
D:PAI(D;;DTSD;;;S-1-5-21-<SID>)(A;OICI;FA;;;SY)(A;OICI;FA;;;S-1-5-21-<SID>)(A;OICI;FA;;;S-1-5-21-<SID>)(A;OICI;FA;;;DA)(A;OICI;FA;;;BA)
- Paste this line underneath the folder names
|
Folder 1 D:PAI(D;;DTSD;;;S-1-5-21-<SID>)(A;OICI;FA;;;SY)(A;OICI;FA;;;S-1-5-21-<SID>)(A;OICI;FA;;;S-1-5-21-<SID>)(A;OICI;FA;;;DA)(A;OICI;FA;;;BA) Folder 2 D:PAI(D;;DTSD;;;S-1-5-21-<SID>)(A;OICI;FA;;;SY)(A;OICI;FA;;;S-1-5-21-<SID>)(A;OICI;FA;;;S-1-5-21-<SID>)(A;OICI;FA;;;DA)(A;OICI;FA;;;BA) Folder 3 <span style="font-family: 'Courier 10 Pitch', Courier, monospace; font-size: 13px; font-style: normal; line-height: 1.5;">D:PAI(D;;DTSD;;;S-1-5-21-<SID>)(A;OICI;FA;;;SY)(A;OICI;FA;;;S-1-5-21-<SID>)(A;OICI;FA;;;S-1-5-21-<SID>)(A;OICI;FA;;;DA)(A;OICI;FA;;;BA) </span>Folder 4 D:PAI(D;;DTSD;;;S-1-5-21-<SID>)(A;OICI;FA;;;SY)(A;OICI;FA;;;S-1-5-21-<SID>)(A;OICI;FA;;;S-1-5-21-<SID>)(A;OICI;FA;;;DA)(A;OICI;FA;;;BA) |
- Save the file.
NOTE: Make sure you save it in Unicode (UTF-16) format. If you do not then ICACLS will generate an error. I personally used my favorite editor Notepad++ and selected Encoding->Encode in ECS-2 Little Endian.
The error will look something like this:
|
E:\Targetfolder\??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????: The system cannot find the file specified. Successfully processed 0 files; Failed processing 1 files |
- Once this is complete you can run icacls /restore to copy the permissions
icacls E:\Targetfolders\ /restore E:\templates\template.txt
NOTE: There may be a way to output the get-childitem results directly to a Unicode format file, but I did not have the time to research this.