Copy file from one server to another remotely?

TaSMania

ADSM.ORG Member
Joined
Nov 17, 2015
Messages
126
Reaction score
1
Points
0
Anyone has a good program script to copy files from one server to another remotely?
I'm trying to script so that I dont have to manually logon to both servers and copy and paste.
I'd tried Powershell using this but per Google search it seems that -tosession does not work.

$session01 = New-PSSession -Credential $myuserID $mypassword -ComputerName $server001
$session02 = New-PSSession -Credential $myuserID $mypassword -ComputerName $server002
Copy-Item -Path "C:\temp\test.txt" -FromSession $session01 -Destination "C:\Temp\test.txt" -ToSession $session02

dont worry about the -credential I will add this later. I just want it to copy first.
Read-Host "Password" -AsSecureString | ConvertFrom-SecureString | Out-File PSCred.txt
$Pass = cat PSCred.txt | ConvertTo-SecureString
$PSCred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $Pass
 
copy-item didn't work so i'd tried invoke-command and it doesn't like my credential. Could it be because of my special character?

$User="myusername"
$Pass="mypassword contains many special characters"
$session02 = New-PSSession -Credential $myuserID $mypassword -ComputerName $server002
$mycopy = {Copy-Item -Path "C:\temp\test.txt" -Destination "C:\Temp\text.txt" -ToSession $session02}
Invoke-Command -ComputerName server001 -Credential $User,$Pass -ScriptBlock $mycopy
 
without a share it probably won't work that way. Server B cannot know where to look for the file except for itself if C: \ is specified as the path.

Therefore, the call of copy item must run at least via a share \\ server \ temp \ test.txt
 
Back
Top