windowspowershellpermissionsactive-directorycopy

Copy/clone folder permissions to another folder (Windows)


I was stuck with copying the User and Group permissions from one folder to another.

The ask was - Copy one folder's permissions to another folder without copying its contents.

One solution is obvious :-

Get-Acl -Path $source_path | Set-Acl -Path $destination_path

But sometimes Set-Acl fails to copy all the group permissions and setting the correct owner.

I will attach an answer below on how I resolved it.


Solution

  • Robocopy.

    Use Robocopy with /XD and /XF tags.

    Basically, /XD and /XF is used to eXclude Directories and eXclude Files.

    Simply this command would work:

    robocopy $source_folder $destination_path /copy:DATSO /secfix /e /b /MT:128 /XD "*" /XF "*"
    

    If you want logs or anything,

    robocopy $source_folder $destination_path /copy:DATSO /secfix /e /b /MT:128 /XD "*" /XF "*" /log+:$logs_path