Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a file in a shared location that I want to copy over to my local hard drive. However I will not be running as a user that has access to the share. So I want to be able to authenticate under a different login (one which does have the permission) and copy the files.

Is there anything I can do to achieve this?

I tried this command (in a ps1 file):

runas /user:domain\username "copy-file $shareloc $destloc"

I get this error:

RUNAS ERROR: Unable to run - copy-file \\share\some\dir\file.exe C:\dir\file.exe
2: The system cannot find the file specified.

How can I copy a file on a network share using a different login with powershell or batch file?

share|improve this question
is the file actually in the location it is copying from ?, e.g \\share\some\dir\file.exe – Iain Simpson Feb 1 '12 at 23:15
up vote 6 down vote accepted

In a batch file, you can connect to the share with the user option:

net use x: \\share\some /user:username password

then do the copy command as you normally would (either using the drive letter, or using the UNC as in the question), then disconnect from the share with

net use x: /d

(You can put * in place of the password to be prompted for it.)

Disclaimer: I'm not sure if this works in a domain.

share|improve this answer
It does! Thank you! – encee Feb 1 '12 at 23:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .