Copy a file to all computers in LAN network with Windows CMD
Solution 1:
A good starting point in CMD is something like:
xcopy "c:\path\to\file" "\\computername\C$\users\username\appdata\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\"
Or the same thing in Powershell:
Copy-Item "c:\path\to\file" "\\$Computername\C$\users\$username\appdata\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\"
There are certainly ways to loop through a list of users/computers, but it depends on how you plan to define and/or get those lists. You could scan the whole local network for example, but it would be extremely slow. There are also a lot of things on the network to consider like firewall settings or whether the PCs are in a windows domain.
To check access, try browsing to the remote PC by pasting the UNC path into file explorer: \\computername\C$\
. If it prompts you for credentials, you will need to provide them as part of your command as well.
For computers not in a windows domain, you usually need to log in with the username formatted like RemotePCName\Username
. If you are able to log in using windows explorer, then you can try doing the same with Powershell:
# This will prompt you for login credentials
$Credential = Get-Credential
# connect to the remote PC as a specific user
New-PSDrive -Name RemotePC -PSProvider FileSystem -Root \\RemotePC\C$ -Credential $Credential
# Now copy the file using the connection:
Copy-Item "c:\path\to\file" "RemotePC:\users\$username\appdata\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\"