title: Powershell - Struggling to copy file from variable location
body: <p>Ive been banging my head with a powershell script that i've tried a few differnt methods with and was wondering if someone can help? </p>
  
  <p>Unsure at this point if im just doing something silly, thanks in advance</p>
  
  <p><strong>Aim:</strong> </p>
  
  <p>To copy a vbs file from  user's homedrives to a different location, the location of the vbs file changes depending on which user needs account admin doing hence why this needs to be variable. It gets the location from a text file which includes the exact path to go to and a destination which has already been created to copy the files to. </p>
  
  <p><strong>Where I have the issue currently:</strong> </p>
  
  <pre><code>$location = Get-Content C:\Users\Administrator\Desktop\here\drive4.txt | Out-String
  $dest = "C:\Users\Administrator\Desktop\here"
  Get-ChildItem -Path $location | 
  Copy-Item -Destination $dest -Recurse -Container -filter "peruser.vbs"
  write-host $location
  
  Read-Host -Prompt "Press Enter to continue or CTRL+C to quit"
  </code></pre>
  
  <p><strong>The Issue</strong></p>
  
  <p>Please see the below, I have put write host to show the location powershell is trying to reach, as a side note I am able to reach this location fine through file explorer </p>
  
  <p><a href="https://i.stack.imgur.com/FgbqF.png" rel="nofollow noreferrer">Screenshot of error </a> </p>
  
  <p>Error Recieved </p>
  
  <pre><code>Get-ChildItem : Illegal characters in path.
  At C:\Users\Administrator\Desktop\MapNetworkDrives2.ps1:17 char:1
  + Get-ChildItem -Path $location | Copy-Item -Destination $dest -Recurse -Container ...
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidArgument: (\\WIN-7V7GI0R7C...             
  :String) [Get-ChildItem], ArgumentException
      + FullyQualifiedErrorId : ItemExistsArgumentError,Microsoft.PowerShell.Commands.GetChildItemCommand
  
  Get-ChildItem : Cannot find path '\\WIN-7V7GI0R7CFK\homedrives\Onetest$                                                     
  
  ' because it does not exist.
  At C:\Users\Administrator\Desktop\MapNetworkDrives2.ps1:17 char:1
  + Get-ChildItem -Path $location | Copy-Item -Destination $dest -Recurse -Container ...
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : ObjectNotFound: (\\WIN-7V7GI0R7C...             
  :String) [Get-ChildItem], ItemNotFoundException
      + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
  </code></pre>