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

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.



9 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” + “\”


    • 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

  2. Ben Chapman Says:

    Thanks for posting this. Ben

    • baraholka1 Says:

      Hiya Ben,

      I am stoked to assist the Assistant Dean of the IT Department a major University.
      I can haz MCTS ??
      Or maybe Ph. D (Hons.) M.A.(Hons. First-Class), M. Sc. (Electromegnetomitochondrianoectomonomics)

      – Barra

  3. Leo Says:

    Please, I need your help,
    Do you know how I can automate file copying between two servers by Powershell, my case is like this, every time a file is generated in a folder on the first server I need to copy it to another folder on the second server.

  4. Pete McEvoy Says:

    Isn’t it crazy that in this era of massive filesystems with paths that will obviously contain spaces that they make it so inconvenient to use these paths? Why didn’t powershell natively support spaces in paths…

  5. Bsbsnsnsns Says:

    Thanks very much

  6. baraholka1 Says:

    Very much thanks for your thanks very much.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: