Copy files to remote computer

Viewed 7582

As part of project requirement, I am preparing a script to copy the files from local computer to remote servers ( with username and password )

I have tried with below ways for files are 27 KB and 50 MB size

i. Using ReadallBytes and WriteAllBytes this is working for small file 27 KB, where as for 50 MB its taking 100% CPU and taking too much of time

$myfile = [System.IO.File]::ReadAllBytes("C:\Temp\test\a.txt")
$Stat = $null
$session=$null
$session = New-PSSession -computerName $server -credential $user
$Stat = Invoke-Command -Session $session -ArgumentList $myfile -Scriptblock {[System.IO.File]::WriteAllBytes("C:\temp\a.txt", $args)} -ErrorAction Stop

ii. I tried to copy with Copy-Item , but issue is target directory is not mount pointed

$Stat = Invoke-Command -ComputerName $server -ScriptBlock { Copy-Item -Path "C:\Temp\test\a.txt" -Destination "C:\temp\a.txt" -Recurse -Force -PassThru -Verbose } -Credential $user

Struck in both ways, please suggest any other way to achieve without mounting the target folder

2 Answers
Related