Run a script located at a remote machine which inturn access files from a network share

by Sanjeev on January 30, 2011

I recently ran into the below issue.

I was trying to execute a powershell script located at a remote machine using the below command and it works great

The above script in-turn copies files from a network share (using robocopy) – It fails complaining the location doesn’t exist. Note that box1 already had access to \\share1 and the script works fine when ran from the box itself, but fails when ran from a remote machine.

Solution 1: Using CredSSP.

Problem : Is not supported in Win 2003 and XP machines.

Solution 2: Run another ps1 script before executing the install.ps1 script to use credentials for the share.

Problem : I didn’t like this solution as the password is exposed as a clear text in the remote machine.

Solution 3 : Run the net use command from the local machine before executing install.ps1 command.

Problem : Again I didn’t want to type the net use command everytime I had to trigger a remote powershell execution. Also I didn’t want to store then in a text file at my local workstation.

Solution 3: Adding the below line to the profile.ps1 file in the remote machine. Remember this doesn’t work if you are trying to trying to access a network resource in a different domain.

Now everytime I invoke powershell to execute the script file “install.ps1″, the shared location can be accessed as a drive “SharedLocation”.

Sweet! My passwords are safe. In case if you want to access a network share located in a different machine, you may find this post useful.