How do I issue a remote copy command?

1.1k views Asked by At

The script I'm working on right now performs a bunch of work on the email server for processing Litigation hold requests. One of the components of this script is to copy all the data from an identified folder on a file server to a secure backup location that can't be altered which happens to reside on the same remote server. I have the script working fine but it copies all the files across the network from the file server to the email server where the PowerShell script is run and then pushes it right back to the same file server it came from to the "hold" folder. This is creating severe delays as some of these folders are several thousands of files ranging from a few bytes to several meg each.

I'm looking for a way for my PowerShell script running on the email server to issue a remote command to the file server to copy a folder from one directory to another (all on the same remote server). Any suggestions?

Currently, I'm using the robocopy command in my script but I'm open to other ways of performing this.

robocopy "Source Folder" "Destination Folder" /e

I'm looking for something like:

PSEXEC \\\FileServer -s -d Copy "Source folder" to "Destination folder"

I just can't seem to find any material on the old google train that satisfies the situation.

2

There are 2 answers

0
Ansgar Wiechers On BEST ANSWER
psexec \\fileserver -s robocopy "source" "destination" /e

should work just fine. With PSRemoting enabled on the fileserver you could also do

Invoke-Command -Computer fileserver -Scriptblock {
  & robocopy "source" "destination" /e
}

Note that this assumes local paths on the remote server. If you're working with network shares on the remote host you'll be running into the second hop problem.

0
Stephen Rushton On

For some strange reason the first attempt to use PSEXEC prior to posting resulted in an error stating it didn't know how to handle the command. But I plugged in the PSEXEC command again and it worked perfectly today.

Thank you.