Copy file to multiple computers

Posted on 2009-02-11
Last Modified: 2013-11-25

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

Question by:connelvalentine
    LVL 76

    Expert Comment

    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.
    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.
    LVL 10

    Expert Comment

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


    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""")
    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.")
    ElseIf Not oFSO.FileExists( sFileToCopy ) Then
    	Wscript.Echo ("Invalid file specified: " & sFileToCopy )
    ElseIf Not oFSO.FileExists( sServerList ) Then
    	Wscript.Echo ("Invalid server list specified: " & sServerList )
    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
    			sLog = sLog & vbCrLf & vbCrLf & "CopyFile( '" & sFileToCopy & "', '" & sLocationToCopy & "' ) ERROR - " & sList(X) & " - Unknown Error!"
    		End If
    		lSuccess = lSuccess + 1
    	End If
    MsgBox( "Processed: " & lSuccess & vbCrLf & "Failed: " & lErrors)
    If lErrors > 0 Then
    	Wscript.Echo ("Error Log: " & vbCrLf & sLog )
    End If 

    Open in new window

    LVL 66

    Accepted Solution

    Put the file in an open share.....
    Text file atc:\PCNames.txt

    PsExec v1.94

    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....
    LVL 66

    Expert Comment

    And no scripting needed... Thats the main reason I suggest this. Takes local commands, and makes them available to use remotely....

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
    Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now