none
POWERSHELL - How to Copy a different set of .csv files to multiple computers based on a particular value given in input file RRS feed

  • Question

  • I'm doing a script to copy a CSV File to multiple computers.

    I have 5 different CSV Files - 12.csv, 34.csv, 56.csv, 78.csv & 910.csv

    I have one input file like below with multiple hostnames

    12 abc
    12 efg
    34 hij
    34 klm
    56 nop
    56 qrs
    78 tuv
    78 wxy
    910 zab
    910 cde

    Now I have to copy

    12.csv to computers abc & efg 

    34.csv to computers hij & klm

    56.csv to computers nop & qrs

    78.csv to computers tuv & wxy

    910.csv to computers zab & cde

    • Moved by Bill_Stewart Thursday, December 20, 2018 8:36 PM Unanswerable drive-by question
    Friday, October 12, 2018 10:39 AM

All replies

  • You forgot to post your script and you have not asked a question.


    \_(ツ)_/

    Friday, October 12, 2018 10:52 AM
  • # This file contains the list of servers you want to copy files/folders to
    $computers = gc "C:\servers.txt"
     
    # This is the file/folder(s) you want to copy to the servers in the $computer variable
    $source = "C:\abc.csv"
     
    # The destination location you want the file/folder(s) to be copied to
    $destination = "C$\Windows\"

    foreach ($computer in $computers) {
    if ((Test-Path -Path \\$computer\$destination)) {
    "\\$computer\$destination Folder exist"
    Copy-Item $source -Destination \\$computer\$destination -Recurse
    } else {
    New-item -itemtype directory -path \\$computer\C$\NEW
    Copy-Item $source -Destination \\$computer\$destination -Recurse
    }
    }

    Friday, October 12, 2018 11:48 AM
  • You forgot to post your code as code, and you have not asked a question.
    Friday, October 12, 2018 12:15 PM
  • Microsoft does not allow you to use the Windows system folder for private files.  It can cause issues with Windows and updates may delete your files.


    \_(ツ)_/

    Friday, October 12, 2018 12:24 PM
  • Sorry what is the question here? Your example code does not include the linking data that you originally posted, just the list of server, source and destination. Are you having trouble parsing the input data or is it something else?
    Monday, October 15, 2018 4:28 AM