title: How do I copy multiple files from multiple hosts in powershell?
body: <p>I am trying to make a powershell script (5.1) that will copy several files and folders from several hosts, these hosts change frequently therefore it would be  ideal if I can use a list that I can append when required.</p>
  
  <p>I have this all working using xcopy so I know the locations exist. I want to ensure that if a change is made when I am not In work someone can just add or remove a host in the text file and the back up will continue to work.</p>
  
  <p>The code I have is supposed to go through each host in my list of hosts and copy all the files from the list of file paths before moving onto the next host.</p>
  
  <p>But there are 2 errors showing up:</p>
  
  <blockquote>
    <p>The term '\REMOTEHOST\c$\Users\Public\desktop\back-up\$Computers' is not recognized as the name of a cmdlet, function, script 
    file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    At line:8 char:17</p>
  </blockquote>
  
  <p>and:</p>
  
  <blockquote>
    <p>copy-item : Cannot find path '\HOST\C$\LK\Appdata\Cmmcfg  C$\LKAppData\Errc  C$\LK\Appdata\TCOMP  C$\LK\Probes  C$\LK\Appdata\CAMIO  C$\LK\Appdata\LaunchPad  C$\LK\Appdata\Wincmes 
    C$\barlen.dta  C$\Caliprogs  C$\Cali' because it does not exist.</p>
  </blockquote>
  
  <p>This does not seem to reading through the list as I intended, I have also noticed that the HOST it is reading from is 6th in the list and not first.</p>
  
  <pre><code>REM*This file contains the list of hosts you want to copy files from*
      $computers = Get-Content 'Y:\***FILEPATH***\HOSTFILE.txt'
  
  REM*This is the file/folder(s) you want to copy from the hosts in the $computer variable*
      $source = Get-Content 'Y:\***FILEPATH***\FilePaths.txt'
  
  REM*The destination location you want the file/folder(s) to be copied to*
      $destination = \\**REMOTEHOST**\c$\Users\Public\desktop\back-up\$Computers
  
      foreach ($item in $computers) {
  
      }  
  
      foreach ($item in $source) {
  
      }
  
      copy-item \\$computer\$source -Destination $destination -Verbose
  </code></pre>