5

So I'm trying to copy 44k files from one server to another.

My Powershell script is:

Import-CSV f:\script\Listoffiles.csv | foreach $line {Move-item $_.Source $_.Destination}

With the Format for the CSV:

Source, Destination  
E:\folder1\folder2\file with space.txt, \\1.2.3.4\folder1\folder2\file with space.txt

I keep getting:

A positional parameter cannot be found that accepts argument '\\1.2.3.4\folder1\folder2\file'.
At line:1 char:10
+ move-item <<<<  E:\folder1\folder2\file with space.txt \\1.2.3.4\folder1\folder2\file with space.txt
    + CategoryInfo          : InvalidArgument: (:) [Move-Item], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.MoveItemCommand

So I've tried putting "s around both paths, and also 's, and I still get either Move-Item: Could not find a part of the path errors.

Can anyone help me?

  • 1
    Use the Code Block markdown instead of <code> tags :) – MDMarra Jun 16 '12 at 2:47
3

Have you tried placing the quotes around the Move-Item params instead of the csv items? Plus, drop the $line variable.

Import-CSV f:\script\Listoffiles.csv | foreach {Move-item "$_.Source" "$_.Destination"}
  • Thanks for the heads up. Ultimately I got it to kinda work by dropping $line, but then I had a ton of problems with characters that wouldn't escape properly. So I ended up doing one massive batch file using Move that worked. – Driftpeasant Jun 20 '12 at 14:47
  • if you have an example of data that didn't work, could you add it here? I'd be interesting to find a solution that always works. – uSlackr Jun 20 '12 at 16:37
  • The two that cause problems were formatted like "name1 & name2.txt" - The script returned an error for the ampersand even though the overall path was quoted out. Similarly "Blahblah (1st and 2nd).txt" would throw an error for the parenthesis enclosed data even though the path was quoted out. – Driftpeasant Jun 20 '12 at 18:33

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.