locked
Command works in local script but fails in remote script RRS feed

  • Question

  • Hi all;

    We have a specific piece of software that we are getting rid of and moving to a different piece of software.   

    I created a script that will do the following:

    1) Stop service X

    2) Uninstall program X

    3) Delete folder X1

    4) Delete folder X2

    5) Install program Y.

    The line that installs program Y looks like this.  &"\\MyServer\Share\My Folder\ProgramName\Setup.exe" /q /s Arg1

    I copy this script to the computers I need to run it on and then I open ISE in admin mode and run the script.  This works perfectly.

    However with lots of computer labs to do I thought I'd create a remote version of this.

    The remote script first query's Active directory and gets a list of computers in a specified OU.  

    Then it looks something like this.

    $command = {1) Stop service X

    2) Uninstall program X

    3) Delete folder X1

    4) Delete folder X2

    5) Install program Y}

    Then a ForEach command will step through the list of computers and then do Invoke-Command to run $command.

    This remote script works perfectly till it gets to step 5.  Then I get an access denied.

    I'm at a loss as to figure out how to get around the access denied.  I suspect it has something to do with the script being run from computer 1 against a list of remote computers which then have to run the installer from MyServer.

    All and any comments would be greatly appreciated.

    WD

    Thursday, November 22, 2018 3:22 AM

Answers

All replies

  • You must copy the installation file to the remote computer.  They cannot be installed from a remote computer.  This is a fundamental restriction of Windows.


    \_(ツ)_/

    Thursday, November 22, 2018 3:32 AM
  • Thursday, November 22, 2018 3:33 AM
  • Thanks for your input.  But I'm still perplexed.

    Why does it work when I run the local script?  Both scripts are calling the install program from the server.

    WD


    Thursday, November 22, 2018 3:43 AM
  • You cannot access a third server from a remote session with normal remoting.  That is clearly addressed in the linked article.

    You can enable CredSSP, use a constrained endpoint or copy the installer file to the remote server.


    \_(ツ)_/

    Thursday, November 22, 2018 8:04 AM
  • Thanks a bunch.   After replying to you I read ComputerScott's post and realized what was going on.

    Would it make a difference if the install was on a share that is open to everyone with full control?

    Thanks to all.

    WD

    Thursday, November 22, 2018 4:14 PM
  • No.  The restriction is not a permissions issue.  It is a system security restriction that can only be circumvented using the methods outlined.

    You can also use GP Software distribution or SCCM.  It is also possible to install software using DSC.

    Save a headache and just copy the file to the target before running the install then delete the package when the install finishes.


    \_(ツ)_/

    • Marked as answer by Witchdoctor12 Thursday, November 22, 2018 5:25 PM
    Thursday, November 22, 2018 4:59 PM
  • Thanks that is what I'll do.

    WD

    Thursday, November 22, 2018 5:24 PM