6

PowerShell Script: Setting NTFS Permissions in Bulk

Posted by Tao Yang on 01/07/2010 in PowerShell |

Today I wrote this PowerShell script to apply a same set of NTFS permission for a particular user or group to a list of folders. It reads the list of folders from a file that is specified from a parameter, apply the permission which is also specified  from parameters. The useage is as follow:

.\BulkSet-NTFSPermissions.ps1 -FolderListFile x:\xxxx\xxxx.txt -SecIdentity “Domain\Group” -AccessRights “FullControl” -AccessControlType “Allow”

  • FolderListFile: a flat text file containing the list of path that need to apply the NTFS permission. It needs to list one folder per line. the path can be a absolute local path such as C:\temp or a UNC path such as \\computer\C$\temp.
  • SecIdentity: The security identity (such as a user account or a security group) the permission is applied for.
  • AccessRights: type of access rights, such as FullControl, Read, ReadAndExecute, Modify, etc..
  • AccessControlType: Allow or Deny

This script checks the permission before applying for it. if the user / group already has the permission that we specified to a folder from the list, it will skip this folder and move to the next one. I had to use this script to grant a group full control rights to over 9000 folders. It only took around 40 minutes to run. I was very impressed!

Tags: ,

6 Comments

  • egs says:

    Hi, i thought i might be able to modify your script – but I just can’t work it out. Have looked at powershell and vb script but it seems very complicated.

    I have a fileserver and need to change the structure and make every file/folder read-only from the top down. I could just set it to read only at the root directory but of course I need to maintain the security groups and users for what has already been defined on folders. We are implementing a new document management system which is why i need to do this.

    Any idea how I could go about this one…???
    Thanks for any help!

    • Tao Yang Tao Yang says:

      Hi egs,

      You can firstly apply your desired permission on your root folder. then prepare a list using this powershell command:
      Get-ChildItem -path [root folder] -recurse | where-object {$_.PSIscontainer} | select Fullname | out-file C:\temp\list.txt

      and pass C:\temp\list.txt into my script (dont forget to firstly remove the header from C:\temp\list.txt first).

      Good Luck
      Tao

  • Matt B. says:

    Thanks for the nice script. Quick question about the -AccessRights switch. Where can I find out what I’m allowed to set here? I’m looking for granular settings, but I’m not sure how to add them with this script.

    Cheers,
    Matt

  • Jeremy says:

    Do you know if it’s possible to apply permissions using a script based on the folder level? For instance, X:\level-01\level-02\level-03…

    I would like use the same AD groups for all three levels. However, only select groups will have “modify” permissions to level-01 and level-02, while the others will have “read-only”. However, I need all groups to have “modify” permissions on level-03.

    Currently, we have the following
    1 x Level-01 folder
    1,200 x Level-02 folders
    10+ x Level-03 folders per Level-02 folder

    If you know of anyway to automate this process, I would greatly appreciate your help in pointing me in the right direction. As of now, I am considering the use of CACLS.exe and AutoIT to automate the process by reading in the folder structure and then applying the CACLS script as needed.

    Thank you.

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Copyright © 2010-2012 Tao Yang's System Management Blog All rights reserved.
This site is using the Desk Mess Mirrored theme, v2.0, from BuyNowShop.com.