0

I have a requirement to copy files from local computer to remote machines,

using the below command but its not working, please help

$Stat = $null
$Source = "C:\Temp\test\"
$Destination = "C:\temp\"

$Stat = Invoke-Command -ComputerName $server -ScriptBlock {
    Copy-Item -Path $Source -Destination $Destination
} -Credential $user

Error:

Cannot bind argument to parameter 'Path' because it is null.
    + CategoryInfo          : InvalidData: (:) [Copy-Item], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.CopyItemCommand
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
sunny
  • 61
  • 2
  • 12
  • `-Force -PassThru -Verbose` try adding this at the of of $Destination – AutoTester213 Aug 11 '17 at 08:23
  • @WojtekT What is that supposed to change about the fact that `$Source` is empty inside the scriptblock (as the error message clearly states)? – Ansgar Wiechers Aug 11 '17 at 08:30
  • I'm not sure thats the best duplicate to link to. Was there not one that used `Invoke-Command`? – Mark Wragg Aug 11 '17 at 08:31
  • Still its not working, please suggest how to copy from local computer to Remote computer with Credentials (FYI: version of powershell is 3.0 in my system, because of this not able to use -ToSession option) I tried with readallbytes and writeallbytes, it is very slow for 35 MB file (took almost 10 mins+) Please suggest the command to copy file to remote with credential – sunny Aug 11 '17 at 09:51
  • That's an entirely different question. For copying from the local to a remote computer you need access to a file share. Use `New-PSDrive` to map a shared folder of the remote host on the local computer, then `Copy-Item` the file(s) to the mapped drive. – Ansgar Wiechers Aug 11 '17 at 10:46
  • 1
    @MarkWragg That's the best one I had in my bookmarks. ;) I added another link to a question explicitly about `Invoke-Command`. – Ansgar Wiechers Aug 11 '17 at 10:50

0 Answers0