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.


    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


    Wednesday, June 06, 2012 4:59 PM


  • 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


    $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}



    Yan Li

    Yan Li

    TechNet Community Support

    Tuesday, June 12, 2012 2:42 AM

All replies