Interactive Bat file to send Files across Network to PCs

Moise Julien 1 Reputation point
2021-11-25T21:42:58.377+00:00

I need help with creating a batch script, which will allow me to send some files across to PCs on the Network. I need the script to be interactive so that it requests the name of the PC to which the file will be sent.

Instead of editing the script whenever I want to send the file to a new PC, I would like the option to enter the PC's name or even a list of PCs to receive the file.

Here is the example of the file being sent
xcopy "C:\Users\James\Work Files\Updated File.xlsx" "\PC NAME\c$\Users\Marco\Desktop"

When the script asks for the 'Send to PC', I can simply enter something like **TeamServ1**, and the file will be sent to **TeamServ1**
xcopy "C:\Users\James\Work Files\Updated File.xlsx" "\TeamServ1\c$\Users\Marco\Desktop"
or pertaining to the request, I can enter a list similar to this:

TeamServ1, TeamServ2, TeamServ3, TeamServ4, TeamServ5

or perhaps the script could ask, **Send to another PC**, or **Finished** (**F**), and I can enter them one after another and when done, I simply enter F like so below

Send to PC
(PC NAME ENTERED) TeamServ1 "Keyboard Enter"

Send to another PC or Finished (F)
(PC NAME ENTERED) TeamServ2 "Keyboard Enter"

Send to another PC or Finished (F)
(PC NAME ENTERED) TeamServ3 "Keyboard Enter"

Send to another PC or Finished (F)
(PC NAME ENTERED) TeamServ4 "Keyboard Enter"

Send to another PC or Finished (F)
(PC NAME ENTERED) TeamServ5 "Keyboard Enter"

Send to another PC or Finished (F)
(F Command ENTERED) F "Keyboard Enter"

I don't have much knowledge on how to make interactive scripts, so if someone could help me out, I would really appreciate it.
Thank you in advance!

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
12,040 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 35,416 Reputation points
    2021-11-26T03:45:06.107+00:00

    Do you have any programming experience in any language?

    I don't recommend .bat files. Powershell has more features and the experience will position you better for future support tasks. Here is a great document to help you get started.

    https://www.sapien.com/books_training/Windows-PowerShell-4

    The Microsoft documentation is here.

    https://learn.microsoft.com/en-us/powershell/scripting/overview?view=powershell-5.1

    In Powershell scripts, you can call executables like xcopy.exe or you can user cmdlet's like Copy-Item.

    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/copy-item?view=powershell-5.1

    Let's start by considering how your script will function. You posted:

    xcopy "C:\Users\James\Work Files\Updated File.xlsx" "\\PC NAME\c$\Users\Marco\Desktop"  
    xcopy "C:\Users\James\Work Files\Updated File.xlsx" "\\TeamServ1\c$\Users\Marco\Desktop"  
    

    It would appear that you have 2 classes of machines, end users desktops and multi-user servers. So for desktops you need "PC NAME", and you also need "Marco". Unless everyone in your organization is named Marco! On multi-user servers, you have the same issue. But it's one machine name and many user names.

    I doubt very much that you will want to type in multiple machine names plus the user names. So the preferred method would be to read in a .CSV file and process it.

    Before we write any code, we need to understand what data you have access to. Do you have a list of every user on every machine that the file needs to be distributed to? That simplifies the code if you can generate a .CSV file that contains 2 columns, MachineName and UserName.

    If you only have the machine name, we can programatically look for user names, but we will want to exclude IIS worker process names and other local accounts that do not apply. Do your users already have the file on their desktop? If so, we can test to see if the file exists and just replace it. But you also have have the problem of what to do if the file is in use and the copy fails.

    I can help you write the script, but I will need more info on your environment.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.