Using Robocopy to copy all users' documents folder, original file name not being retained after copy.

Marvin Mathieu 21 Reputation points
2023-01-17T21:59:19.7733333+00:00

We have a share on our old fileserver and the files going to it are the local users' documents folder that has been redirected to the server. The documents folder is set to have the domain accounts username as the title of the folder but since doing a robocopy job to a new file server, about a third of the folders have their title displayed as 'Documents' rather than their domain account username. On the old server their names are still correct.

Any suggestions on this issue besides changing them back one by one?

docfolname

Windows Server 2019
Windows Server 2019
A Microsoft server operating system that supports enterprise-level management updated to data storage.
3,882 questions
Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
5,741 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Miloslav Ďurina 0 Reputation points
    2023-01-18T01:06:39.7966667+00:00

    quite tired,

    but if the name of the folder is really a username (samaccountname) and users still rely on the original data (you are able to delete the copy and re-run robocopy), it should work...

    • replace path in $source with your source parrent folder of the user folders
    • replace path in $targetpath with your intended destination parrent path
    • replace "your_domain" in $domainuser with your domain
    • add your robocopy options

    another approach, if the user is owner of the folder, could be read that attribute and try to rename all the folders using it

    $source = "path"
    get-childitem $source -directory | foreach-object {
        $foldername = $_.name
        $sourcepath = "$source\$foldername"
        $targetpath = "path\$foldername"
        $domainuser = "your_domain\$foldername"
        new-item -path $targetpath -itemtype directory -erroraction silentlycontinue | out-null
        $acl = get-acl $targetpath
        $rights = "modify"
        $inheritance = "containerinherit, objectinherit"
        $propagation = "none"
        $accesscontrol = "allow"
        $rule = new-object system.security.accesscontrol.filesystemaccessrule("$domainuser","$rights","$inheritance","$propagation","$accesscontrol")
        $acl.addaccessrule($rule)
        set-acl $targetpath $acl
        robocopy $sourcepath $targetpath
        }
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.