Search code examples
powershellntfs

Getting NTFS permissions through Powershell and piping the output to set the same permissions in a different location


I am moving CIFS share files and subfolders from one system to another, and I want to set the top level folder at the destination to have same ACLs as the top level folder at the source. In some cases this is up to 25 users and groups.

Is there a way to get the ACLs from the source top level folder, and pipe that output so it is applied to the top level destination folder?


Solution

  • You can copy an ACL very easily:

    Get-Acl -Path <SourceFolder> | Set-Acl -Path <DestinationFolder>
    

    But this isn't very eloquent. It will only take the ACL from one folder and apply it to another. Given you are going to copy a whole tree your milage may vary.

    Robocopy is often used in these situations with the /COPYALL parameter. You can create the tree without copying with /CREATE. You may have to tinker around to get it to do only one folder. Hard to say without knowing the particulars of your project, but if you're interested check the help file.

    I'd also point out, there is an awesome NTFS module here. I use it all the time it's very capable, and very easy to script around.

    Let me know if this is helpful.