Maintaining file sharing permissions between servers can be a major challenge, but by using PowerShell we can automate this process so you can get home early.
When you perform a file migration, you do not only have to consider the files and folders themselves, but also the permissions set on those objects. Each file and folder may have a different set of Access Control Entries (ACEs) that make up an Access Control List (ACL). Depending on the number of files you are migrating, this can be a lot.
When you move files to a new location, you don't always get the permissions. When performing a massive migration, such as full file servers with complicated permissions, it is important to keep those permissions with the objects as they move to the new location.
There are a few ways to do this.
A favorite tool to perform file migrations is robocopy . Robocopy is a great tool with lots of bells and whistles, but it can be complicated to use and may not work in all situations. When this happens, I usually look for a tool called icacls . This is a tool that has been around for a long time and, like robocopy has a lot of switches, so let's simplify this tool a bit with some PowerShell.
Using PowerShell to transfer permissions [1
9659008] Although you can use the icacls command-line tool directly, it is not the easiest to understand. To fix this, learn about a PowerShell as a wrapper to call the tool icacls to simplify this sometimes daunting process.
First we need to download an existing tool that has already been created for us. One of the great things about the PowerShell community is that there is usually an existing tool to help us. In this case we need a PowerShell module. This PowerShell module can be found in the PowerShell Gallery.
If you have PowerShell v4 or higher, you already have some commands to grab this module quickly.
PS> Find-Module -Name NTFSPermissionMigration | Installation module
Once the above code is completed, a new module should now be installed on your computer for you to use. Once this installation is complete, we now need to run a command in the module against the folder with all the files we want to transfer rights to.
PS> Save-Acl -FolderPath \\ OLDSERVER FileShare -SaveFilePath C: \ FilePermissions.txt
Once this is done, you should see an output that looks something like this and you will see the save file start to grow.
Processed file: \\ OLDSERVER \ FileShare \ File1.txt processed file: \\ OLDSERVER \ FileShare \ File2.exe X files successfully processed; Cannot process 0 files
When this is finished, you should now have full rights to files and folders in the save file. Now we can recover this file. But before this happens, you need to make an exact copy of all the files in the old folder or it won't work.
To restore the rights to the new folder path, & # 39; d now use the command
PS> Restore-Acl -RestoreToFolderPath \\ NEWFILESERVER \ FileShare -PermissionFilePath C: \ FilePermissions.txt XXX files successfully processed; Cannot process 0 files
Once this is complete, all NTFS permissions should be mirrored from your source folder and the new destination folder!
Using a free PowerShell module from the community and a little bit of script magic can be a daunting task of moving NTFS permissions from one server to another is a piece of cake.