# PSremoting, Copy-Item and UNC paths

• ### Question

• Hello All,

I have a problem whereby I have written a script which works perfectly when ran locally but when I remote execute the script using the Invoke-command cmdlet it gives an error form the remote machine saying that the file I want to copy from the UNC path cannot be found.

The file does exist on the UNC path and the script will work correctly should I log on to the same server and run the script from there.

The script which i want to execute on a remote computer contains a line of code as follows:

copy-item \\unc\path\to\file.zip -destination "C:\Filelocation\"

I then invoke the script using the following:

Invoke-command RemoteComputerName -file "C:\scriptfile.ps1"
I'm new to powershell but haven't heard anything that would explain this issue.

Can anyone help?

Wednesday, April 25, 2012 11:45 AM

### All replies

Wednesday, April 25, 2012 11:52 AM
• Thank for the reply. I've read that but it doesnt make sense.

From what i understand, when a script is remotely executed, the commans have to be written as if you are sitting on the remote machine. So when i execute a command using the invoke-command cmdlet, the execution of whatever I put in the script block shoudl run in the contect of the remote machine. Therefore, if I execute -copy-item \\path -destination c:\path it should work.

Should it not?! I'm a little confused.

Wednesday, April 25, 2012 12:25 PM
• I can't reproduce your error, although I'm doing exactly the same thing.  When I run commands similar to those you posted, the file gets copied as expected, with no errors.

Grant Ward, a.k.a. Bigteddy

What's new in Powershell 3.0 (Technet Wiki)

Wednesday, April 25, 2012 12:49 PM
• I don't see how thats relevant? The first link talks about passing user credentials over multiple hops not copying files. I dont understand the second link as both computers are a member of teh same domain and I am domain admin on both.

I appreciate you replying however you need to do more than post links to be helpful. Perhaps explaining why they are relevant might help? at the moment I am none the wiser as to what is causing my problem.

Wednesday, April 25, 2012 1:04 PM
• Are you in a domain or workgroup environment?

Grant Ward, a.k.a. Bigteddy

What's new in Powershell 3.0 (Technet Wiki)

Wednesday, April 25, 2012 1:06 PM
• As Kazun has indicated its whats called a double hop issue.

the invoke-command is from system A to System B, and on System B you run
your Scriptfile.ps1, which then makes a call to System C via the UNC path...

this is only allowed with CredSSP which is the links he's provided.

Justin Rich
http://jrich523.wordpress.com
PowerShell V3 Guide (Technet)
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
• Proposed as answer by Thursday, April 26, 2012 2:18 AM
• Marked as answer by Thursday, April 26, 2012 10:43 AM
Wednesday, April 25, 2012 1:19 PM
• Thanks. That helps with the explanation.

It doesn't take a lot to write a short beginners explanation. I wish more people would do that instead of coming across as arrogant and frustrated with what is, for them, a basic question.

Thursday, April 26, 2012 10:42 AM
• that’s why im here :)

kazun is by far one of the smartest guys in here, but English is a second
language to him so he comes up with the answer and I explain it :)

Justin Rich
http://jrich523.wordpress.com
PowerShell V3 Guide (Technet)
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Thursday, April 26, 2012 1:09 PM
• that’s why im here :)
kazun is by far one of the smartest guys in here, but English is a second
language to him so he comes up with the answer and I explain it :)

Justin Rich
http://jrich523.wordpress.com
PowerShell V3 Guide (Technet)
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

Yes, I think sometimes people think he's just being lazy by posting links.  His links are always completely relevant.  I've never come across someone who could pinpoint a problem as quickly and accurately as Kazun.  He is THE master!

Grant Ward, a.k.a. Bigteddy

What's new in Powershell 3.0 (Technet Wiki)

Thursday, April 26, 2012 1:23 PM