Powershell - Copy a list of files to multiple servers and backup exisiting files

Hello..

I would like to have assistance from Powershell gurus..

My scenario is; I want to automate a task to copy some .dll files from one location to multiple servers but before copying those files over to those servers; I'd like to take a backup for those same files which will be overwritten on to a local server where these .dll files will be copied from

My preference would be that the script should read 1 file (.txt or .csv) which will contain the name of those files that need to be copied over and get backedup and then read another file which will contain the list of servers.

example

File to copy = filename.dll (this filename.dll should be read from a .txt or .csv file which could contain more than 1 file)

Server to copy to = server1, server2, server3 (this should be read from a .csv file)

From the local server; Read filename(s).dll from the file, the servername from the server file and before copying the new files over, copy those exact same files from the shared folders on those servers and paste them on the local server by creating a folder as the servername and paste the file in there.

Then copy the new files over to those servers from the list and overwrite the existing files.

I really appreciate your time and effort in this

Thanks

June 6th, 2012 7:59pm

Hi,

This is a very simple powershell script to transfer a file to a list of computes contained in a text file.

#Point the script to the text file
$Computers = Read-Host "Enter Location Of TXT File"
# sets the varible for the file location ei c:\temp\ThisFile.exe
$Source = Read-Host "Enter File Source"
# sets the varible for the file destination
$Destination = Read-Host "Enter File destination (windows\temp)"
# displays the computer names on screen
Get-Content $Computers | foreach {Copy-Item $Source -Destination \\$_\c$\$Destination

Or:

$a = Get-Content "D:\Scripting\Srvlist.txt" foreach ($i in $a) {$files= get-content "D:\Scripting\filelist.txt"

foreach ($file in $files)

{Copy-Item $file -Destination \\$i\C$\temp -force}

}

Regards,

Yan Li

Free Windows Admin Tool Kit Click here and download it now
June 12th, 2012 5:42am

Hi ,

There is a way to get log from the second script? I mean, log which files were copied?

September 12th, 2014 6:08pm

Hi ,

There is a way to get log from the second script? I mean, log which files were copied?

You can use the -PassThru switch:

http://ss64.com/ps/copy-item.html

If you have additional questions, please start your own thread.

Free Windows Admin Tool Kit Click here and download it now
September 12th, 2014 6:13pm

thank You! And sorry about that.
September 12th, 2014 8:33pm

Cheers, you're welcome.
Free Windows Admin Tool Kit Click here and download it now
September 12th, 2014 8:49pm

Thanks this helped a lot!

But is there a way to read a text file which contains the source paths of multiple files which you want to copy to multiple computers?

Using the same process which allows you to put multiple computers in a text file. 

Thanks in advance, 

Tom 

October 24th, 2014 5:29pm

Hello,

How about copying MULTIPLE FILES to MULTIPLE SERVERS.

Above script is all about copying single file to all servers.

In my scenario, i do not want to copy a folder instead i would like to pickup few from it. i.e more than 1.

regards,

Dharanesh,


Free Windows Admin Tool Kit Click here and download it now
February 25th, 2015 1:02am

Hello,

How about copying MULTIPLE FILES to MULTIPLE SERVERS.

Above script is all about copying single file to all servers.

In my scenario, i do not want to copy a folder instead i would like to pickup few from it. i.e more than 1.

regards,

Dharanesh,


Please start your own thread. You'll need to post your code and your errors.

February 25th, 2015 8:26am

Hello,

How about copying MULTIPLE FILES to MULTIPLE SERVERS.

Above script is all about copying single file to all servers.

In my scenario, i do not want to copy a folder instead i would like to pickup few from it. i.e more than 1.

regards,

Dharanesh,


  • Edited by Dharanesh Wednesday, February 25, 2015 6:00 AM
Free Windows Admin Tool Kit Click here and download it now
February 25th, 2015 8:59am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics