Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
1  
Use the Code Block markdown instead of <code> tags :) –  MDMarra Jun 16 '12 at 2:47
    
Thanks for the tip! –  Driftpeasant Jun 20 '12 at 14:47

1 Answer 1

up vote 2 down vote accepted

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}"
share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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