locked
Copy Folder & files to remote servers RRS feed

  • Question

  • I am using simple powershell script to copy  files from  local system to remote servers. i am using  same command by changing  sever name every time

    Copy-item -path "c:\softwares\xyz.exe" -destination "\\server1\c$\temp"

    Copy-item -path "c:\softwares\xyz.exe" -destination "\\server2\c$\temp"

    Copy-item -path "c:\softwares\xyz.exe" -destination "\\server3\c$\temp"

     it is very tough if i have to  do the same thing for more then 15 server.

    please help me with some script.

    server name can be picked from  1 txt file like 

    It will be very much used if it ask for 2 credentials

    it should check server connectivity with domain credential 

    if it fails then it should check for remote server local admin credential

    where credentials can be store in some variable when domain credential fails it should take remote server local admin credential 

    serer name from C:\servers.txt


    Thanks, jeevan



    Tuesday, July 2, 2013 5:09 PM

Answers

  • sorry i didnt actually look at your code yeah one line of copy should do it since its same, umm as far as seeing if it copied you could do

    if(test-path "\\$server\c$\temp\xyz.exe"){

    "xyz.exe copied to $server"

    }

    • Marked as answer by Jeevan.bobba Tuesday, July 2, 2013 5:58 PM
    • Unmarked as answer by Jeevan.bobba Wednesday, July 3, 2013 4:05 PM
    • Marked as answer by Bill_Stewart Monday, August 19, 2013 6:12 PM
    Tuesday, July 2, 2013 5:38 PM

All replies

  • you would do

    $servers = get-content c:\servers.txt foreach($server in $servers){

    Copy-item -path "c:\softwares\xyz.exe" -destination "\\$server\c$\temp"

    Copy-item -path "c:\softwares\xyz.exe" -destination "\\$server\c$\temp"

    Copy-item -path "c:\softwares\xyz.exe" -destination "\\$server\c$\temp"

    }


    Tuesday, July 2, 2013 5:12 PM
  • Hello imMax,

    instead of  doing this  

    $servers = get-content c:\servers.txt
    foreach($server in $servers){
    Copy-item -path "c:\softwares\xyz.exe" -destination "\\$server\c$\temp"
    Copy-item -path "c:\softwares\xyz.exe" -destination "\\$server\c$\temp"
    Copy-item -path "c:\softwares\xyz.exe" -destination "\\$server\c$\temp"
    }
    

    can i use this once 

    $servers = get-content c:\servers.txt
    foreach($server in $servers){
    Copy-item -path "c:\softwares\xyz.exe" -destination "\\$server\c$\temp"
    }

    will this help full ?

    add how will i know weather it got copied or not

    how about authentication or access 


    Thanks, jeevan

    • Marked as answer by Jeevan.bobba Tuesday, July 2, 2013 5:58 PM
    • Unmarked as answer by Jeevan.bobba Wednesday, July 3, 2013 4:05 PM
    Tuesday, July 2, 2013 5:24 PM
  • sorry i didnt actually look at your code yeah one line of copy should do it since its same, umm as far as seeing if it copied you could do

    if(test-path "\\$server\c$\temp\xyz.exe"){

    "xyz.exe copied to $server"

    }

    • Marked as answer by Jeevan.bobba Tuesday, July 2, 2013 5:58 PM
    • Unmarked as answer by Jeevan.bobba Wednesday, July 3, 2013 4:05 PM
    • Marked as answer by Bill_Stewart Monday, August 19, 2013 6:12 PM
    Tuesday, July 2, 2013 5:38 PM
  • How about Authentication part.

    Thanks, jeevan

    Tuesday, July 2, 2013 5:49 PM
  • you can pass -credential to copy-item
    Tuesday, July 2, 2013 5:50 PM
  • it should check for  domain credential 1st, if that faild then it should  check for  remote server local admin credentials credentials should be save in some  variable

    Thanks, jeevan

    Tuesday, July 2, 2013 5:57 PM
    • Proposed as answer by smstesty Friday, October 27, 2017 7:46 PM
    Tuesday, July 2, 2013 6:31 PM
  • How to enter Local Admin  credentials of remote server

    Thanks, jeevan

    Wednesday, July 3, 2013 2:46 AM
  • Hi,

    This question is already marked as answered. If you still need help, please start a new question.

    Bill

    Wednesday, July 3, 2013 1:48 PM