Hi SysAdmins
In an earlier post I described – How to copy files to domain member computers or servers using Group Policy Object (GPO).
In this post I will show how to copy files to remote computers or servers using a simple Powershell script and .txt file.
All you need is:
A txt file that looks like this:
Server1.yourdomain.com
Server2.yourdomain.com
Server3.yourdomain.com
and so on…
You can use IP addresses as well.
And this piece of Powershell code:
[code lang=”powershell”]
$ServerList = Get-Content "C:\ServersList.txt" #Change this to location of servers list
$SourceFileLocation = #For example: D:\FoldertoCopy\ or D:\file.txt
$Destination = #Example: C$\temp
foreach ($_ in $ServerList)
{Copy-Item $SourceFileLocation -Destination \\$_\$Destination -Recurse -PassThru}
[/code]
Save the above code as CopyFilestoservers.ps1, and your servers list as ServersList.txt
You will need Write permissions on the remote machines to run the script successfully.