how to give a username full control to files and subfolders within a folder RRS feed

  • Question

  • How can I use PowerShell to give a user NTFS permissions for full control of every file and subfolder within a folder? 
    Wednesday, May 29, 2019 7:52 PM

All replies

  • Using set-acl cmdlet or icacls ..  if u dont have disabled inheritance on subfolders/files then its easy.  Otherwise, u have to loop through all files and folders. 
    Wednesday, May 29, 2019 8:38 PM
  • Hi,

    You can find a lot of examples online if you do some searching, I also suggest you check the TechNet Gallery for examples, it's a good source to check for scripts. As mentioned earlier, you can use the Set-Acl cmdlet or icacls.

    Here's a simple example with PowerShell:

    # Get the ACL for an existing folder
    $ExistingACL = Get-Acl -Path 'C:\Temp'
    # Sets Full Control permission for the given user on This Folder, Subfolders and Files
    $Permissions = 'DOMAIN\Username', 'FullControl', 'ContainerInherit,ObjectInherit', 'None', 'Allow'
    # Create a new FileSystemAccessRule object
    $Rule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $Permissions
    # Modify the existing ACL to include the new rule
    # Apply the modified access rule to the folder
    $ExistingACL | Set-Acl -Path 'C:\Temp'

    Best regards,

    Blog: https://thesystemcenterblog.com LinkedIn:

    Wednesday, May 29, 2019 10:09 PM