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.

{ 5 comments… read them below or add one }

mushoku November 22, 2011 at 5:18 PM

I’m trying your solution and not having any success. I’ve added the New-PSDrive lines to my $profile on the remote machine, as well as %windir%\system32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1 . Even so, I am unable to see the PSDrives when executing Invoke-Command from my system.


Sanjeev December 3, 2011 at 10:42 AM

What error are you getting ? Are you trying to access two machine in the same domain and does the user account you are using has access to the target machine as an administrator?


Tom January 21, 2012 at 7:48 AM

Found your Post via Stackoverflow, hope your solution will solve my problems 😉 Thanks for sharing!


kiquenet May 30, 2012 at 5:07 AM

Any final solution with full source code ?

I want call to powershell script (in local) that run another script located in the same local machine, but run it in remote machine,

and I want call to powershell script (in local) that run another script located in remote machine, but run it in remote machine,



szumigalski February 15, 2017 at 6:13 PM

VMware Certified Advanced Professional 6 (Desktop and Mobility Deployment) – The industry-recognized VCAP6-DTM Deploy certification validates that you know how to deploy and optimize VMware Horizon 6 (with View) environments. It demonstrates that you have the understanding and abilities necessary to leverage best practices to provide a scalable and reliable Business Mobility platform for your company. Some of the subjects involve: Configuring and managing Horizon View components, configuring cloud pod archituecture, configuring Group Policy settings related to Horizon View, Configuring and optimizing desktop images for Horizon View & Mirage, Configuring and managing App Volumes AppStacks, Configuring desktop pools, Configuring and deploying ThinApp packaged applications, Configuring VMWare Identity Manager, was designed by Sebastian to propagate his love for PowerShell & VMWare. Sebastian is an IT skilled professional employed in Singapore for over 15 years who’s routinely on the lookout for cutting edge technological innovation to improve his technical competencies & understanding. Ever since, Sebastian has joined up with PowerShell User Group & VMWare VMug group, and has also been getting involved in all of the meetings held in Singapore. This website will highlight exactly how Sebastian are able to automate some of his daily works making use of PowerShell. You will discover study guides readily available for the VCAP6-DTM examination, which were personally created by Sebastian. Sebastian is qualified with VCAP6-DTM, and is well-informed with virtualization & server maintenance from four years experience of automation. The demand for VMWare prepared admins and engineers are ever-increasing in the modern tech industry. Learn much more about PowerShell & VMWare with!


Leave a Comment

Previous post:

Next post: