Powershell, remote script access denied to network resources

Szymon Kuzniak picture Szymon Kuzniak · Oct 17, 2011 · Viewed 13.8k times · Source

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

Answer

manojlds picture manojlds · Oct 17, 2011

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