1

I am currently migrating from a Unix FS to a Windows FS and i need to copy user folders. I have created a robocopy script that is very simple with a few kinks here and there.

My script:

@echo off set /p username=Enter Username to start copying files: echo %username% takeown /f \UNIXFS\users$%username%* /r /D N timeout /t 3 robocopy \UNIXFS\users$%username% \WINDOWSFS\Production$%username% /S /E /B /Z /ZB /MT:64 /V /TEE /ETA /TS /R:5 /W:1 /BYTES /X /DEBUG /LOG:C:\Robocopy%username%.log timeout /t 3 icacls \WINDOWSFS\Production$%username%* /grant:r domain%username%:(OI)(CI)F /T pause

I have an input section asking me which user i would like to start copying files from and too.

i take owner ship from the user as the current domain admin, copy the files and give the user full permissions on the folder.

But the ownership is still for the domain admin and not the user chosen by the inputted user.

Therefor i have created a separate single command line bat file that will take the ownership of the folder when i log in to the users account.

Take ownership script to run on for the migrated user: takeown /F \WindowsFS\Production$%username%* /r /D Y

is there a way i can combine these two script as one and just run this as a single script.

I have tried to just combine them both together but the last takeown command like just give the user that runs the script ownership, when you have to do this for a lot of users you don't want to manually input or run the takeown script one by one on all machines.

cbraafhart
  • 11
  • 1
  • 1
    you tried to use ICACLS to change the owner? You could use: ICACLS /setowner /T – AzureBaum Jul 15 '21 at 08:14
  • Yes i did try to use /setowner but it does not take the user that i would like to set. it takes the current logged in user or the user running the batch script. And as of taking ownership of the folder that i want to copy, i have read the following from a post: " Note that the icacls command with the /setowner option doesn’t allow you to forcibly change the file system object ownership. If you are not the current object owner, use the takeown.exe command to replace the file or folder ownership." – cbraafhart Jul 15 '21 at 13:44
  • But you could set the owner on your user account with takeown and then set a new with icacls. We usally set the owner on the local administrator group (takeown with /a). – AzureBaum Jul 15 '21 at 19:15

0 Answers0