Maintaining file share permissions across servers can be a major challenge but by using PowerShell, we can automate this process allowing you to go home early.
When doing any file migration, you not only have to consider the files and folder themselves but also the permissions set on those objects. On each file and folder could potentially be a different set of Access Control Entries (ACEs) that make up an Access Control List (ACL). Depending on how many files you're migrating this can be alot.
When moving files to a new location, the permissions don't always come with them. When doing a massive migration like entire file servers with intricate permissions in place, it's important to keep those permissions with the objects as they move to the new location.
There are a few ways to do this.
One 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'll usually look into a tool called icacls. This is a tool that's been around for a long time and, like robocopy, has a lot of switches so let's simplify this tool a little bit with some PowerShell.
Using PowerShell to Transfer Permissions
We're going to be using PowerShell as a wrapper around the icacls tool to simplify this sometimes daunting process.
First, we'll need to download an existing tool that's already created for us. One of the great things about the PowerShell community is that there's usually an existing tool out there to help us out. In this case, we're going to need a PowerShell module. This PowerShell module can be found in the PowerShell Gallery.
If you have PowerShell v4 or later you'll already have some commands to grab this module quickly.
Find-Module -Name NTFSPermissionMigration | Install-Module
Once the code above is done, you should now have a new module installed on your computer available for use. Once this is done, we'll now need to run a command inside of the module against the folder containing all of the files we'd like to transfer permissions on.
Save-Acl -FolderPath \\OLDSERVER\FileShare -SaveFilePath C:\FilePermissions.txt
Once this is run, you should see an output similar to this and begin to see that save file start to grow.
processed file: \\OLDSERVER\FileShare\File1.txt processed file: \\OLDSERVER\FileShare\File2.exe Successfully processed X files; Failed processing 0 files
When this is complete, you should now have all of the permissions for files and folders inside of the save file. Now we can restore this file. Before this happens, though, be sure to do an exact copy of all the files inside of the old folder otherwise, this will not work.
To restore the permissions to the new folder path, we'd now use the
Restore-Acl -RestoreToFolderPath \\NEWFILESERVER\FileShare -PermissionFilePath C:\FilePermissions.txt Successfully processed XXX files; Failed processing 0 files
Once this is complete, all NTFS permissions should be mirrored from your source folder and the new destination folder!
Using a free community PowerShell module and a little bit of scripting magic can turn a daunting task of moving NTFS permissions from one server to another a piece of cake.
Join the Jar Tippers on Patreon
It takes a lot of time to write detailed blog posts like this one. In a single-income family, this blog is one way I depend on to keep the lights on. I'd be eternally grateful if you could become a Patreon patron today!Become a Patron!
Subscribe to Adam the Automator
Get the latest posts delivered right to your inbox