How to Transfer File Permissions with PowerShell
Maintaining file share permissions throughout servers is usually a main problem however by utilizing PowerShell, we are able to automate this course of permitting you to go dwelling early.
When doing any file migration, you not solely have to contemplate the information and folder themselves but in addition the permissions set on these objects. On every file and folder may doubtlessly be a unique set of Access Control Entries (ACEs) that make up an Access Control List (ACL). Depending on what number of information you’re migrating, this is usually a lot.
When shifting information to a brand new location, the permissions don’t at all times come with them. When doing a large migration like total file servers with intricate permissions in place, it’s necessary to hold these permissions with the objects as they transfer to the brand new location.
There are just a few methods to do that.
One favourite software to carry out file migrations is robocopy. Robocopy is a good software with plenty of bells and whistles, however it may be sophisticated to use and will not work in all conditions. When this occurs, I’ll often look right into a software known as icacls. This is a software that’s been round for a very long time and, like robocopy, has a number of switches, so let’s simplify this software a bit of bit with some PowerShell.
Using PowerShell to Transfer Permissions
Although you should utilize the icacls command-line utility instantly, it’s not the best to perceive. To treatment this, you’re going to find out about a PowerShell as a wrapper to invoke the icacls software to simplify this typically daunting course of.
First, we’ll want to obtain an present software that’s already created for us. One of the nice issues in regards to the PowerShell group is that there’s often an present software on the market to assist us out. In this case, we’re going to want a PowerShell module. This PowerShell module may be discovered within the PowerShell Gallery.
If you may have PowerShell v4 or later, you’ll have already got some instructions to seize this module shortly.
PS> Find-Module -Name NTFSPermissionMigration | Install-Module
Once the code above is completed, it’s best to now have a brand new module put in in your pc accessible to be used. Once this set up is completed, we now want to run a command within the module in opposition to the folder containing the entire information we’d like to switch permissions on.
PS> Save-Acl -FolderPath OLDSERVERFileShare -SaveFilePath C:FilePermissions.txt
Once that is run, it’s best to see an output related to this and start to see that save file begin to develop.
processed file: OLDSERVERFileShareFile1.txt processed file: OLDSERVERFileShareFile2.exe Successfully processed X information; Failed processing 0 information
When that is full, it’s best to now have the entire permissions for information and folders within the save file. Now, we are able to restore this file. Before this occurs, although, make certain to do an actual copy of all of the information within the previous folder, in any other case this is not going to work.
To restore the permissions to the brand new folder path, we’d now use the
PS> Restore-Acl -RestoreToFolderPath NEWFILESERVERFileShare -PermissionFilePath C:FilePermissions.txt Successfully processed XXX information; Failed processing 0 information
Once that is full, all NTFS permissions ought to be mirrored out of your supply folder and the brand new vacation spot folder!
Using a free group PowerShell module and a bit of little bit of scripting magic can flip a frightening process of shifting NTFS permissions from one server to one other a chunk of cake.
This Web site is affiliated with Amazon associates, Clickbank, JVZoo, Sovrn //Commerce, Warrior Plus etc.