Hi,
I'm trying to copy a file from a server on an enterprise network to a specific location on a number of multiple computers in the same network using PSExec and I've got some problems that I wanted to ask you.
First of all, I'm executing these commands from a Virtual machine executing Windows Server 2012 R2 in a local user with administrative rights and using the same credentials I want to use to access the computers.
So this is what I'm doing on my execute.bat:
@echo off
for /F %%a IN (computers.txt) DO (
psexec \\%%a -u %%a\<localAdminUser> -p <password> -i -c "\\server1\Folder\CopyFile.bat") >> \\server1\Folder\log3.txt 2>>&1
Right now, computers.txt has only 1 PC, which is mine that is running Windows 10, and we're gonna name it <mylaptop>. \server1 is accessible by every computer on the network with their domain account.
And then, on \server1, this is the CopyFile.bat:
copy "\\server1\Folder\File.xml" "C:\Users\%username%\AppData\Folder"
When I first run execute.bat on my server, nothing happens...I first need to remotely access \server1 using my domain account, and only then I'm able to run execute.bat, and I get this on the log3.txt file:
PsExec v2.4 - Execute processes remotely
Copyright (C) 2001-2022 Mark Russinovich
Sysinternals - www.sysinternals.com
Connecting to <mylaptop>...
Starting PSEXESVC service on <mylaptop>...
Copying authentication key to <mylaptop>...
Connecting with PsExec service on <mylaptop>...
Copying \server1\Folder\CopyFile.bat to <mylaptop>...
Starting \server1\Folder\CopyFile.bat on <mylaptop>...
C:\WINDOWS\system32>copy "\server1\Folder\File.xml" "C:\Users\<localAdminUser>\AppData\Folder"
Username or password is incorrect
CopyFile.bat exited on <mylaptop> with error code 1.
So...it doesn't work. And there's also another problem here, because he is using <localAdminUser> instead of using the domain username that has a active session on the computer, which is what I want when I'm using %username% on the CopyFile.bat. It only works if I use my domain account and use it in the Execute.bat instead of using the <localAdminUser>, like this:
@echo off
for /F %%a IN (computers.txt) DO (
psexec \\%%a -u <enterpriseDomain>\<myDomainUser> -p <password> -i -c "\\server1\Folder\CopyFile.bat") >> \\server1\Folder\log3.txt 2>>&1
But doing this is impossible because, obviously, I cannot access every computer on the domain with my username and password, I really need to use the first option where I use the local admin user which is the same in every computer.
What do you think I should do?