Powershell: Copy File on Remote Computer When Path Has Spaces In It

By baraholka1

Dear Imaginary Audience,

This one depleted my life force by about 37 mins, so I am figuring it might help some of you others, even though it is simple to the point of trivial.

I have a remote computer called BRUCE:
There is a file called YouLittleRipper.txt contained in the following Path:
C:\Program Files\Microsoft\Mammoth App Folder

To copy YouLittleRipper.txt from another computer NARELLE in Powershell do the following:
- Start Powershell On Narelle
$RipperPath = "\\BRUCE" + "\" + "C$" + "\"Program Files\Microsoft\Mammoth App Folder" + "\"
$Source = $RipperPath + "YouLittleRipper.txt"
$Target = $RipperPath + "OnyaGranny.txt"
copy-item "$Source" "$Target"

The file “OnyaGranny.txt” will now exist on BRUCE in ‘Mammoth App Folder”.

The secret ingredient is to put the quotation marks around the whole path after it has been constructed in the variable $Source.

You owe me 37 mins. Give us it.

Tags:

2 Responses to “Powershell: Copy File on Remote Computer When Path Has Spaces In It”

  1. Jay Lushmen Says:

    you’ve listed the source and target paths as being the same path…is this intentional? It would seem that if you want to copy a file from Narelle to Bruce you would do something like this:
    $source = “\\Narelle” + “\” + “C$” + “\”Program Files\Microsoft\Mammoth App Folder” + “\”
    $target = “\\BRUCE” + “\” + “C$” + “\”Program Files\Microsoft\Mammoth App Folder” + “\”

    …correct?

    • baraholka1 Says:

      Hiya Jay,

      That would be correct.
      I was a little unclear in my text.
      What I meant was ‘copying a file on a remote machine to another folder or path on the remote machine’

      But what you say is correct.
      That will achieve copying the file from Narelle to BRUCE.

      Thanks for pointing that out and dropping by for a Bite Of The Wax Tadpole.

      - Barra

Leave a Reply