none
PermCopy Fails Using For Command

    General discussion

  • I am trying to automate the migration of 59 shares from one NAS to another.  (There will be many other migrations besides this one.)  So far I have successfully used remtshare.exe in a batch file to create the shares with default perms on the target server, using a list from the source server.

    I now need to copy the Share permissions from the source server to the target.  I am trying to use permcopy.exe against a list of shares:

    for /f %x in (copyshares.txt) do permcopy \\source %x \\target %x >>log1.log

    This fails with "The process cannot access the file because it is being used by another process."  But if I just type "permcopy \\source <sharename> \\target <sharename>", using one of the share names from copyshares.txt, it succeeds, so I know the command itself works.

    I can't spot anything in the "for" line that seems wrong.  If I change the text file to one that contains server names, and change the command to: "for /f %x in (servers.txt) do ping %x", it succeeds, so my syntax seems to be okay as well.

    If anyone can tell me why it fails, that would be great.  If anyone knows of a better (free) solution for migrating shares, even better.  Keep in mind that the solution needs to be something that can be run against remote source and target, because they are NASes (not Windows).

    Thanks. 

    Tuesday, August 31, 2010 9:14 PM

All replies

  • I would like to make sure if the "file is beiing used" means the copyshares.txt is being used --- Have you trid to do the same command after reboot, or make a copy of the file and using the new file?

    Meanwhile whether robocopy is available? Just a thought. If it is available then /secfix parameter should help.


    Shaon Shan| TechNet Subscriber Support in forum| If you have any feedback on our support, please contact tngfb@microsoft.com
    Wednesday, September 01, 2010 6:45 AM
  • Thanks for the reply.

    I have run the command using the same text file on different machines with the same negative result.  I have also created a new file that contains just a few of the names listed in copyshares.txt, but I had the same error.

    I already am using Robocopy as a migration tool, but it doesn't copy Share permissions.  I need to migrate the shares and permissions after migrating the data (and NTFS perms) using Robocopy.

    Wednesday, September 01, 2010 1:34 PM
  • Hi,

    Have a test on following commands:

    1. permcopy \\source share1 \\target share1

    permcopy \\source share2 \\target share2

    If both work, try add share1 and share2 to a new txt file share12.txt, and try for /f %x (share12.txt) do permcopy \\source %x \\target %x


    Shaon Shan| TechNet Subscriber Support in forum| If you have any feedback on our support, please contact tngfb@microsoft.com
    Tuesday, September 07, 2010 12:48 AM
  • I had already tried something similar, but I did just what you suggested. 

    It was successful when run as a straight command on 2 different share names.  If failed when run against a text file which contains the same 2 share names:  "The process cannot access the file because it is being used by another process."

    The same syntax works when using a command other than permcopy.exe, so I have to assume that there is some kind of bug with the utility that causes the problem.  Instead, I'll try using an Excel spreadsheet that contains the share names in 2 columns, then use the concatenate function to combine those columns with other columns that contain the command syntax.  Then I'll copy it all into a batch file.  This should work, but I'll let you know.

    Thanks. 

    Wednesday, September 08, 2010 4:46 PM
  • Usings the Excel concatenate method worked.  It took a lot of editing, but it did the work.

    Cheers.

    Wednesday, September 08, 2010 8:59 PM