Powershell, remote access script to network resources

I am trying to execute a powershell script remotely using the invoke command. The script relies on a configuration file accessible over the local network. The script is invoked as follows:

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

The configuration you see is an xml file and is loaded with:

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

When the script is called locally on the machine, it runs without any problems and reads the configuration file. However, when I run it from another computer using the invoke command, I get

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

which is called when the Load method is executed.

The file is accessible to everyone with read and write permissions. Both the machine on which the script should run (.181) and the machine on which it is running have the same credentials, so I do not pass them on the command-command cmdlet. The share machine (.1) has different credentials, but this has never been a problem when calling the script locally from .181.

Could you point me in the right direction? I have followed this step and cannot find a solution on my own. I tried to load the XML string using the WebClient # DownloadString method and passing the credentials to the shared computer, but that did not help.

Thanks in advance

+6
source share
1 answer

This is probably a double hop problem. You must use CredSSP to delegate your credentials to a remote computer.

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

+9
source

Source: https://habr.com/ru/post/899460/


All Articles