Change NTFS security on some folders

Everyone working in IT stumbled over the cursed problem, to change the ACL on a set of folders or files.

First you define the folder or the file(s) to be changed.

Then you collect the filesystem objects from the path variable with the following command.

The following foreach-loop reads the acl for every item in the target list. Then the permission for the additional acl is defined and with a .NET object it will be converted to an access rule.

The new access rule is added to the acl object and the object itself will be piped back to the item with the Set-Acl cmdlet.

So, have fun and be sure you always have a backup from the acl of your files, before you start messing around with this script.

Leave a Reply

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