8

I am trying to execute powershell script remotely using invoke-command. The script relies on a configuration file which is available over the local network. The script is called in a following way:

Invoke-Command -ComputerName 192.168.137.181 -FilePath c:\scripts\script.ps1 -ArgumentList \\192.168.137.1\share\config.xml

The configuration as you can see is an xml file and it's loaded using:

$xml = New-Object XML
$xml.Load(args[0])

When the script is called locally on the machine then it runs witout any problems and reads the configuration file. However when I run it from different machine using invoke command I get

"Access to the path '\\192.168.137.1\share\config.xml' is denied"

exception, which is thrown when executing Load method.

The file is accessible to everyone with read and write permissions. Both, machine on which the scrip should be run (.181) and the machine on which it is run physically have the same credentials, thus I do not pass them in invoke-command cmdlet. The share machine (.1) has different credential, but this was never an issue when calling the script locally from .181.

Can you please point me in the right direction? I stuck on this step and can't find solution by myself. I tried downloading the xml string using WebClient#DownloadString method and passing credentials for the share machine but it did not help.

Thanks in advance

Szymon Kuzniak
  • 848
  • 1
  • 6
  • 16

1 Answers1

8

It is probably a double hop issue. You have to use CredSSP to delegate your credentials to the remote computer.

Try the solution mentioned here: http://blogs.msdn.com/b/clustering/archive/2009/06/25/9803001.aspx

manojlds
  • 290,304
  • 63
  • 469
  • 417
  • 1
    Thanks for your answer. I already tried solution for double hop problem. Note that I do not need any specyfic credential, as the file is accessible to everyone (or at least it should be). Also I tried solution with WebClient and explicitly passing network credentials into it and it did not help either. I'll give it another try however as soon as I get back to work. – Szymon Kuzniak Oct 17 '11 at 19:58
  • +1 for CredSSP. Thanks! This works for me, allowing the access of files on the network, as well as making authenticated requests against IIS. – Zach Bonham May 29 '12 at 19:05
  • There is an insight of the double hop problem. https://learn.microsoft.com/en-us/powershell/scripting/learn/remoting/ps-remoting-second-hop?view=powershell-7.1 – Camilo Acevedo. Jul 21 '21 at 01:49