Error when accessing UNC paths through powershell script when remoting - visual-studio-2010

I am trying to execute a program inside of a power shell script. The PS script is being called from a C# method using Runspaces. The program tries to make an update to a config file on a remote server. When I run this whole thing I get the following error:
System.UnauthorizedAccessException: Access to the path \\some path is denied.
The PS script is on a remote server. If I run the PS script directly on the server then the PS script and the program inside of it runs fine and is able to access the remote system.
Has anyone run into this before? I was told that this is failing because I am running it through Visual Studio and C# and that I won't be allowed to access network resources through a powershell script that is being run through a C# class. Someone else told me that the permissions that I am using to start the PS script in the runspace are not translating to the program that I am calling within the script.
Other ideas and possible solutions?
Thanks

It looks like you're trying to modify a file on a UNC path on a secondary server. This won't work due to the age old "double hop" problem. You are on machine A, executing a remote script on B that tries to modify a file on C. Your authentication from A to B cannot be reused to connect from B to C. This is a design limitation for NTLM (windows integrated authentication.)
However, all is not lost: You must use CredSSP authentication when connecting with powershell remoting from A to B, and then you can connect to C without a problem.
References:
http://tfl09.blogspot.ca/2013/02/powershell-remoting-double-hop-problem.html
http://www.ravichaganti.com/blog/?p=1230

Related

Android studio not running .sh script with Jsch

Whenever I try to execute a sh script via Jsh nothing happens , however when I execute it through a normal ssh session it works fine , I haven't been able to get a single sh file to work/run regardless of the contents of the sh file.
I have tried
channelssh.setCommand("/home/exiatron00/Desktop/bash test.sh");
channelssh.setCommand("/home/exiatron00/Desktop/./test.sh");
channelssh.setCommand("/home/exiatron00/Desktop/test.sh");
I don't see anything wrong with your command, so I would have to assume it's your setup.
Are you sure you're even logging into your server? I would check your last logs to make sure you are even connecting.
Are you on the same network as the machine you're attempting to connect to? If you aren't on wifi I would assume your machine is hidden behind a NAT.

Executing remote bat located on the remote computer

I need to execute a bat file located on several remote computers from my administration computer.
When I run it on the different remote computers I have no problem executing it.
When i run a "call myRemoteBat" from my local computer on all the remote ones my script doesn't run properly, raising for example the issue "foo not recongnized as an internal command"
Is there a way in the "call" command to execute using all the remote variables data?
Thanks

parallel execution of multiple system commands on a single unix host from windows

I need to execute multiple system commands in parallel on a remote unix machine(only through ssh) from my windows machine.
I have used paramiko module to do the ssh to the remote machine. In the same script, I have used python subprocess module to fire the commands in parallel on the remote machine.
But I am unable to do it . Could anyone please let me know how to achieve this scenario using subprocess module? or any other way to look into the problem?
My line of code where it is not working is :
processes.append(Popen(task,shell=True)) ----> task is getting executed on my own windows machine and not getting executed on the remote unix machine. it gives me a error an windows error. Also I don't know whether my subprocess code will work for achieving parallel runs here.
But I am successful in achieving parallel runs with the same piece of code using subprocess module if I copy the code to the unix machine and run the script locally.
Problem comes when I am executing the code from the windows machine and doing ssh to the remote machine.
What about Fabric ? http://docs.fabfile.org/en/1.10/usage/parallel.html
I always use it for such purposes.

Executing Perl Script From Linux Box Using SSH Causing "The local device name is already in use"

I have a Perl script which maps two drives, and then proceeds to copy files one of the drives to the other. The Perl script is located on a Windows box, but we are SSHing from a Linux box into the Windows box to execute the script. When I run the script directly from the Windows box, everything works without issue, the drives are mapped and the files are copied over successfully. When I attempt to execute the script from my Linux box via SSH, the script fails and I get the following output:
The local device name is already in use.
Error mapping source \\xxx.xxx.net\localdirectory
This error occurs when attempting to map the first drive, I don't know if it would fail on the second drive as well since it has not made it that far.
I have several other Perl scripts that are executed this same way (via ssh from Linux to Windows box) and they execute without issue, this is the only one that maps a drive though. This is the code I am using to execute the script:
#!/bin/sh
ssh -t -t user#server "cd /Path/to/Perl/Script; /cygdrive/C/Perl/bin/perl.exe Script.pl"
What user is your ssh daemon running as? Presumably System. That user doesn't have authority to map network drives, as far as I recall. Can you not just do this on the Linux box directly using samba?
In case anyone needs this in the future, we we're able to get it working. The issue was due to the SVCCopSSH being used for the CopSSH service on our Windows machine. We had to disable the CopSSH service, set the Log On as the network account we were using to SSH from Linux to Windows, and restart the service. This fixed all issues we were having.

Install .exe software application on remote machines

I modified this script from the net, which is suppose to install .exe applications for remote machines:
$m = Read-Host "Enter machine name"
$File = "c:\temp\office2007sp2-kb958194-fullfile-en-us.exe"
$product = [WMICLASS]"\\$m\ROOT\CIMV2:win32_Process"
$product.Create($File)
When I run this script, I have noticed that this program promptly creates a process in the remote machine with the application name office2007sp2-kb958194-fullfile-en-us.exe.
This can be checked in the task manager also.
But other than that, there is no way to find out if this is getting installed in the remote machine or not.
Is there a way to find out, if the installation is really happening?
Or does this script actually works?
Not a proper answer because I haven't tried remote process launching like that, but I have used psexec to launch processes on other machines.
If you are still having problems with your script you may want to check out ps_exec, it lets you execute processes on other machines as if it was your own. You can check the exit code of the process just like you would if you were executing the process locally.
It's offered as a free tool by microsoft: http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

Resources