map drives and copy files with psexec

What am i doing wrong here? I can get it to map the drive but apparently the drive goes away once i end the psexec session.
when i try to copy the file over with the next psexec command it tells me the drive doesn't exist
please help
@echo off
setlocal EnableDelayedExpansion 
	set /p "ip_address=Enter IP address:"
	set /p "target=Enter computer Manager(2),Training(3):"
	for /f %%a in ("%ip_address%") do (
		for /F "tokens=1,2,3 delims=."  %%i in ("%%a") do (
			set other_ip=%%i.%%j.%%k.%target%
			)
		echo !other_ip! is the Target computer
		psexec -u administrator -p twash01 \\%%a -i cmd /s /c net use z: "\\!other_ip!\c$" "password" /user:administrator 
		psexec \\%%a -u administrator -p twash01 copy c:\source\team*.reg z:\temp -y
		psexec \\%%a -u administrator -p twash01 cmd.exe /c net use z: /delete
	)

Open in new window

im wanting to remote into one computer and share a drive on it and then copy files to the other computer all locally on the remote system . this will make file distripution faster instead of having to send to all computers. I can just send it to one computer and let it copy to the others locally.
Thanks!
bbimisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shaun VermaakTechnical Specialist/DeveloperCommented:
For one, you can speed it up by adding line 10-11 to a batch then use the -c parameter to copy and execute it on a computer.

Secondly, you do not need to do a loop. PSExec support using a list with @file
Usage: psexec [\\computer[,computer2[,...] | [b]@file[/b]]][-u user [-p psswd][-n s][-l][-s|-e][-x][-i [session]][-c [-f|-v]][-w directory][-d][-<priority>][-a n,n,...] cmd [arguments]

Open in new window

0
oBdACommented:
Would have failed with the "copy" anyway - "copy" is an internal command of cmd.exe, so it won't work all by its lonesome.
Try it like this:
@echo off
setlocal EnableDelayedExpansion 
set /p "ip_address=Enter IP address:"
set /p "target=Enter computer Manager(2),Training(3):"
for /f %%a in ("%ip_address%") do (
	for /F "tokens=1,2,3 delims=."  %%i in ("%%a") do (
		set other_ip=%%i.%%j.%%k.%target%
	)
	echo !other_ip! is the Target computer
	psexec.exe -u administrator -p twash01 \\%%a -i cmd.exe /c "net.exe use z: "\\!other_ip!\c$" "password" /user:administrator & copy c:\source\team*.reg z:\temp -y & net use z: /delete"
)

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Shaun VermaakTechnical Specialist/DeveloperCommented:
Thirdly, that mapped drive will not be visible to any user except administrator
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

bbimisAuthor Commented:
obda i tried your solution and got an exit error of 0 but it did not copy the files over any suggestion?
0
oBdACommented:
Replace the /c after cmd.exe with /k and try again. This will keep the window open, so that you can see error messages.
0
bbimisAuthor Commented:
says the syntax of the command is incorrect.
it appears to be an issue with the copy command cause the drive deletes and it also appears to create
0
bbimisAuthor Commented:
this solution worked the only issue was the copy command and it was changed to
xcopy c:\source\team*.reg z:\temp /e /y

works fine now thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.