I often have to copy files and folders from one server to another for various reasons. Copying stuff manually is a bore but if you are only copying to a couple of servers it is quicker to do it manually but if you have to copy to several servers it would be quicker to use a script. We can leverage PowerShell to perform this task.
We will use the Copy-Item cmdlet in PowerShell. It will copy file and folders to a remote server using the following syntax:
Copy-Item “source” -Destination “\\server\C$”
To make it a little but more sophisticated we will add a check to confirm that the remote servers’ path exists using the Test-Path cmdlet before performing the copy. If the path does not exist it will state that it “is not reachable or does not exist”:
# This file contains the list of servers you want to copy files/folders to
$computers = gc “C:\scripts\servers.txt”
# This is the file/folder(s) you want to copy to the servers in the $computer variable
$source = “C:\Software\EMC\Networker\NWVSS.exe”
# The destination location you want the file/folder(s) to be copied to
$destination = “C$\temp\”
foreach ($computer in $computers) {
if ((Test-Path -Path \\$computer\$destination)) {
Copy-Item $source -Destination \\$computer\$destination -Recurse
} else {
“\\$computer\$destination is not reachable or does not exist”
}
}
OR
#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}
}
fe1l7h
qe9kea
3gwktm
a5oies
vdwm84
sz397l
I like what you guys are up too. Such clever work and reporting! Carry on the excellent works guys I have incorporated you guys to my blogroll. I think it will improve the value of my web site 🙂
t75fkq
o6mhac
jfkiwo
o8igm7
3kke5w
I love it when people come together and share opinions, great blog, keep it up.
5chwhm
g0v9ri
Hello my family member! I want to say that this post is amazing, great written and come with approximately all important infos. I would like to peer extra posts like this .
Hi my family member! I wish to say that this article is amazing, nice written and include approximately all important infos. I would like to look extra posts like this .
a2fbdg
d78nlq
hfkuls
hv54fx
xmim4w
You are a very intelligent individual!
j9yo7w
Very interesting points you have noted, thankyou for posting.
Hi, i think that i saw you visited my web site so i came to “return the favor”.I’m trying to find things to improve my site!I suppose its ok to use some of your ideas!!
Thanks , I have just been looking for info about this subject for ages and yours is the greatest I have discovered so far. But, what about the bottom line? Are you sure about the source?
7xvco8
We are a gaggle of volunteers and opening a new scheme in our community. Your site offered us with useful information to work on. You’ve performed an impressive activity and our entire neighborhood will probably be thankful to you.
Hey I am so excited I found your site, I really found you by mistake, while I was searching on Digg for something else, Regardless I am here now and would just like to say cheers for a incredible post and a all round enjoyable blog (I also love the theme/design), I don’t have time to look over it all at the minute but I have book-marked it and also included your RSS feeds, so when I have time I will be back to read a lot more, Please do keep up the fantastic job.
I’ve been browsing online more than 3 hours as of late, yet I never discovered any interesting article like yours. It’s beautiful worth enough for me. Personally, if all site owners and bloggers made good content as you probably did, the web will probably be a lot more helpful than ever before. “Oh, that way madness lies let me shun that.” by William Shakespeare.
Some genuinely good information, Gladiola I noticed this.