We help IT Professionals succeed at work.

Copy file to multiple computers

Medium Priority
1,998 Views
Last Modified: 2013-11-25
Hi,

I want to copy a file called xyz.bmp to the c: folder of a list of computers i have on a text file.
I'm in a domain environment without about 50 desktops. My domain user account is the local administrator on all these machines.

I understand the best logical way, is to run a batch file that will read from this text file that hass all the computer name, and execute the copy command for all the computers in the text file.
This is the logic, but I don't have any scripting know how. Could some one please explain how this can be done from scratch?

Thanks in advance

CV.
Comment
Watch Question

CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Do You have a GPO that applies to all the computers, you can add a startup script that will have
copy \\server\share\filename c:\

You could introduce a check to see if the file is present before issueing the copy command.
http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_23983934.html
When the system boot the script will run with system rights and will check whether the file is present if it is missing, it will copy the one from the share.
Top Expert 2008

Commented:
Use this script, save it as C:\Copy.vbs and call it as such from a cmd window.

c:

cd \

cscript Copy.vbs <file> <location> <machinelist>


Option Explicit
 
Dim sFileToCopy
Dim sLocationToCopy
Dim sLocationSplit
Dim lPos
Dim sDriveToCopy
Dim sFolderToCopy
Dim sServerList
Dim sList
Dim oFSO
Dim oStream
Dim X
Dim sLog
Dim lErrors
Dim lSuccess
 
Set oFSO = CreateObject( "Scripting.FileSystemObject" )
lErrors = 0
lSuccess = 0
sLog = ""
 
If WScript.Arguments.Count <> 3 Then
	Wscript.Echo ("Usage: " & vbcrlf & vbcrlf & "cscript " & Wscript.ScriptName & " ""C:\Example.exe"" ""C:\Location"" ""C:\ServerList.txt""")
	Wscript.Quit
End If
 
sFileToCopy = WScript.Arguments.Item(0)
sLocationToCopy = WScript.Arguments.Item(1)
sServerList = WScript.Arguments.Item(2)
 
lPos = Instr( sLocationToCopy, ":" )
 
If ( lPos < 1 ) Then
	Wscript.Echo ("Invalid format for desitantion location.")
	Wscript.Quit
ElseIf Not oFSO.FileExists( sFileToCopy ) Then
	Wscript.Echo ("Invalid file specified: " & sFileToCopy )
	Wscript.Quit
ElseIf Not oFSO.FileExists( sServerList ) Then
	Wscript.Echo ("Invalid server list specified: " & sServerList )
	Wscript.Quit
End If
 
Set oStream = oFSO.OpenTextFile( sServerList )
sList = Split( oStream.ReadAll, vbCrLf )
 
sDriveToCopy = Left( sLocationToCopy, lPos - 1 )
sFolderToCopy = Right( sLocationToCopy, Len(sLocationToCopy) - lPos )
 
On Error Resume Next
 
For X = 0 To UBound( sList )
	sLocationToCopy = "\\" & sList(X) & "\" & sDriveToCopy & "$" & sFolderToCopy
	
	
	If Not oFSO.CopyFile ( sFileToCopy, sLocationToCopy, True )  Then
		lErrors = lErrors + 1
		If Err Then
			sLog = sLog & vbCrLf & vbCrLf & "CopyFile( '" & sFileToCopy & "', '" & sLocationToCopy & "' ) ERROR - " & sList(X) & " - " & Err.Description
			Err.Clear
		Else
			sLog = sLog & vbCrLf & vbCrLf & "CopyFile( '" & sFileToCopy & "', '" & sLocationToCopy & "' ) ERROR - " & sList(X) & " - Unknown Error!"
		End If
	Else
		lSuccess = lSuccess + 1
	End If
Next
 
MsgBox( "Processed: " & lSuccess & vbCrLf & "Failed: " & lErrors)
If lErrors > 0 Then
	Wscript.Echo ("Error Log: " & vbCrLf & sLog )
	Wscript.Quit	
End If 

Open in new window

CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2011
Commented:
Put the file in an open share.....
Text file atc:\PCNames.txt

PsExec v1.94
http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

psexec @pcnames.txt -d copy /Y "\\server\share\xyz.bmp" c:\

-d switch is optional, it just moves on to the next PC name in the list without waiting for the first one to complete....

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2011

Commented:
And no scripting needed... Thats the main reason I suggest this. Takes local commands, and makes them available to use remotely....
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.