Powershell run exe on remote computer using a UNC path t












0















From PC A I'm trying to run this script. It should on PC B run a Exe. The Exe it will run resides on PC C. These are windows 7 OS PCs PC C are server 20082012



 $text ='Start-process -FilePath "\<serverpath>App.exe" "`-f switch`.switch"'
Invoke-Command -ComputerName $PCname -Scriptblock { param ($text)
$text | Invoke-Expression
}


The command in $text runs from the powershell console on the remote PC just correctly.
Running the entire script gives:
This command cannot be executed due to the error: Access is denied.



Doing some research I believe I'm running into the "double hop issue"



Brief description.



You have computer A, B, and C. You want to run a script from A, that has B run a scriptprocess on C. Your credentials won't pass from B to C.



Due to requirements I think using the method of



$cred = Get-Credential ContosoAdministrator
Invoke-Command -ComputerName ServerB -Credential $cred -ScriptBlock {
hostname
Invoke-Command -ComputerName ServerC -Credential $Using:cred -ScriptBlock {hostname}
}


As explained in the link. One issue I think I'm running into is I want the process to run on PC B its only the exe that resides on PC C.










share|improve this question



























    0















    From PC A I'm trying to run this script. It should on PC B run a Exe. The Exe it will run resides on PC C. These are windows 7 OS PCs PC C are server 20082012



     $text ='Start-process -FilePath "\<serverpath>App.exe" "`-f switch`.switch"'
    Invoke-Command -ComputerName $PCname -Scriptblock { param ($text)
    $text | Invoke-Expression
    }


    The command in $text runs from the powershell console on the remote PC just correctly.
    Running the entire script gives:
    This command cannot be executed due to the error: Access is denied.



    Doing some research I believe I'm running into the "double hop issue"



    Brief description.



    You have computer A, B, and C. You want to run a script from A, that has B run a scriptprocess on C. Your credentials won't pass from B to C.



    Due to requirements I think using the method of



    $cred = Get-Credential ContosoAdministrator
    Invoke-Command -ComputerName ServerB -Credential $cred -ScriptBlock {
    hostname
    Invoke-Command -ComputerName ServerC -Credential $Using:cred -ScriptBlock {hostname}
    }


    As explained in the link. One issue I think I'm running into is I want the process to run on PC B its only the exe that resides on PC C.










    share|improve this question

























      0












      0








      0








      From PC A I'm trying to run this script. It should on PC B run a Exe. The Exe it will run resides on PC C. These are windows 7 OS PCs PC C are server 20082012



       $text ='Start-process -FilePath "\<serverpath>App.exe" "`-f switch`.switch"'
      Invoke-Command -ComputerName $PCname -Scriptblock { param ($text)
      $text | Invoke-Expression
      }


      The command in $text runs from the powershell console on the remote PC just correctly.
      Running the entire script gives:
      This command cannot be executed due to the error: Access is denied.



      Doing some research I believe I'm running into the "double hop issue"



      Brief description.



      You have computer A, B, and C. You want to run a script from A, that has B run a scriptprocess on C. Your credentials won't pass from B to C.



      Due to requirements I think using the method of



      $cred = Get-Credential ContosoAdministrator
      Invoke-Command -ComputerName ServerB -Credential $cred -ScriptBlock {
      hostname
      Invoke-Command -ComputerName ServerC -Credential $Using:cred -ScriptBlock {hostname}
      }


      As explained in the link. One issue I think I'm running into is I want the process to run on PC B its only the exe that resides on PC C.










      share|improve this question














      From PC A I'm trying to run this script. It should on PC B run a Exe. The Exe it will run resides on PC C. These are windows 7 OS PCs PC C are server 20082012



       $text ='Start-process -FilePath "\<serverpath>App.exe" "`-f switch`.switch"'
      Invoke-Command -ComputerName $PCname -Scriptblock { param ($text)
      $text | Invoke-Expression
      }


      The command in $text runs from the powershell console on the remote PC just correctly.
      Running the entire script gives:
      This command cannot be executed due to the error: Access is denied.



      Doing some research I believe I'm running into the "double hop issue"



      Brief description.



      You have computer A, B, and C. You want to run a script from A, that has B run a scriptprocess on C. Your credentials won't pass from B to C.



      Due to requirements I think using the method of



      $cred = Get-Credential ContosoAdministrator
      Invoke-Command -ComputerName ServerB -Credential $cred -ScriptBlock {
      hostname
      Invoke-Command -ComputerName ServerC -Credential $Using:cred -ScriptBlock {hostname}
      }


      As explained in the link. One issue I think I'm running into is I want the process to run on PC B its only the exe that resides on PC C.







      powershell exe






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 '18 at 21:33









      MinerbobMinerbob

      16019




      16019
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Remote call from PC-A to PB-B and PC-B needs to run a .exe on PC-C.



          Invoke-Command requires you be admin on whatever target you are trying to hit and that is only for that target.



          Are you saying you tried that last block of code and it failed?



          Because, if all remoting is configured properly, it should work this way.



          $PC_A = 'ws01'
          $PC_B = 'iis01'
          $cred = Get-Credential "$env:USERDOMAIN$env:USERNAME"

          "Running from $env:COMPUTERNAME"
          "Targetng $PC_A"
          Invoke-Command -ComputerName $PC_A -Credential $cred -ScriptBlock {
          "Targeting $Using:PC_B from $Using:PC_A via remote source"
          Invoke-Command -ComputerName $Using:PC_B -Credential $Using:cred -ScriptBlock {"PC_B name is $env:COMPUTERNAME"
          notepad.exe
          Get-Process -Name notepad
          }
          }

          # Results

          Running from DC01
          Targetng ws01
          Targeting iis01 from ws01 via remote source
          PC_B name is IIS01

          Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName PSComputerName
          ------- ------ ----- ----- ----- ------ -- ----------- --------------
          172 10 2184 9424 ...29 0.02 3520 notepad ws01


          You should also look at using PSDrive to the .exe on the second hop instead of the extra remote effort and running the .exe as if it was on the first hop.






          share|improve this answer


























          • Remote call from PC-A to PB-B and PC-B needs to run a .exe on PC-C. Close....Remote call from PC-A to PB-B and PC-B needs to run a .exe Located on PC-C.

            – Minerbob
            Nov 18 '18 at 22:51













          • I get that and that is what I am showing in the sample. $env:computername (your PC-A) is the initial source to target PC-A (your PC-B), PC-A (your PC-B) is the source for PC-B ( your PC-C), executing notepad on PC-B (your PC-A), and that is a non-interactive thing. You can only run an app on any remote host in your own context, not the context of any user on a remote host. PS does not allow this, as it is a security boundary. If you want to run that app in the remote users context, the you have to use a 3rdP tool like psexec from sysinternals.

            – postanote
            Nov 18 '18 at 23:07











          • "You can only run an app on any remote host in your own context" I just need to face facts - I can't do what I want in pure PS. I have a alternate way of doing what I want through scheduling a Altiris job.

            – Minerbob
            Nov 19 '18 at 0:13











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53345710%2fpowershell-run-exe-on-remote-computer-using-a-unc-path-t%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Remote call from PC-A to PB-B and PC-B needs to run a .exe on PC-C.



          Invoke-Command requires you be admin on whatever target you are trying to hit and that is only for that target.



          Are you saying you tried that last block of code and it failed?



          Because, if all remoting is configured properly, it should work this way.



          $PC_A = 'ws01'
          $PC_B = 'iis01'
          $cred = Get-Credential "$env:USERDOMAIN$env:USERNAME"

          "Running from $env:COMPUTERNAME"
          "Targetng $PC_A"
          Invoke-Command -ComputerName $PC_A -Credential $cred -ScriptBlock {
          "Targeting $Using:PC_B from $Using:PC_A via remote source"
          Invoke-Command -ComputerName $Using:PC_B -Credential $Using:cred -ScriptBlock {"PC_B name is $env:COMPUTERNAME"
          notepad.exe
          Get-Process -Name notepad
          }
          }

          # Results

          Running from DC01
          Targetng ws01
          Targeting iis01 from ws01 via remote source
          PC_B name is IIS01

          Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName PSComputerName
          ------- ------ ----- ----- ----- ------ -- ----------- --------------
          172 10 2184 9424 ...29 0.02 3520 notepad ws01


          You should also look at using PSDrive to the .exe on the second hop instead of the extra remote effort and running the .exe as if it was on the first hop.






          share|improve this answer


























          • Remote call from PC-A to PB-B and PC-B needs to run a .exe on PC-C. Close....Remote call from PC-A to PB-B and PC-B needs to run a .exe Located on PC-C.

            – Minerbob
            Nov 18 '18 at 22:51













          • I get that and that is what I am showing in the sample. $env:computername (your PC-A) is the initial source to target PC-A (your PC-B), PC-A (your PC-B) is the source for PC-B ( your PC-C), executing notepad on PC-B (your PC-A), and that is a non-interactive thing. You can only run an app on any remote host in your own context, not the context of any user on a remote host. PS does not allow this, as it is a security boundary. If you want to run that app in the remote users context, the you have to use a 3rdP tool like psexec from sysinternals.

            – postanote
            Nov 18 '18 at 23:07











          • "You can only run an app on any remote host in your own context" I just need to face facts - I can't do what I want in pure PS. I have a alternate way of doing what I want through scheduling a Altiris job.

            – Minerbob
            Nov 19 '18 at 0:13
















          0














          Remote call from PC-A to PB-B and PC-B needs to run a .exe on PC-C.



          Invoke-Command requires you be admin on whatever target you are trying to hit and that is only for that target.



          Are you saying you tried that last block of code and it failed?



          Because, if all remoting is configured properly, it should work this way.



          $PC_A = 'ws01'
          $PC_B = 'iis01'
          $cred = Get-Credential "$env:USERDOMAIN$env:USERNAME"

          "Running from $env:COMPUTERNAME"
          "Targetng $PC_A"
          Invoke-Command -ComputerName $PC_A -Credential $cred -ScriptBlock {
          "Targeting $Using:PC_B from $Using:PC_A via remote source"
          Invoke-Command -ComputerName $Using:PC_B -Credential $Using:cred -ScriptBlock {"PC_B name is $env:COMPUTERNAME"
          notepad.exe
          Get-Process -Name notepad
          }
          }

          # Results

          Running from DC01
          Targetng ws01
          Targeting iis01 from ws01 via remote source
          PC_B name is IIS01

          Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName PSComputerName
          ------- ------ ----- ----- ----- ------ -- ----------- --------------
          172 10 2184 9424 ...29 0.02 3520 notepad ws01


          You should also look at using PSDrive to the .exe on the second hop instead of the extra remote effort and running the .exe as if it was on the first hop.






          share|improve this answer


























          • Remote call from PC-A to PB-B and PC-B needs to run a .exe on PC-C. Close....Remote call from PC-A to PB-B and PC-B needs to run a .exe Located on PC-C.

            – Minerbob
            Nov 18 '18 at 22:51













          • I get that and that is what I am showing in the sample. $env:computername (your PC-A) is the initial source to target PC-A (your PC-B), PC-A (your PC-B) is the source for PC-B ( your PC-C), executing notepad on PC-B (your PC-A), and that is a non-interactive thing. You can only run an app on any remote host in your own context, not the context of any user on a remote host. PS does not allow this, as it is a security boundary. If you want to run that app in the remote users context, the you have to use a 3rdP tool like psexec from sysinternals.

            – postanote
            Nov 18 '18 at 23:07











          • "You can only run an app on any remote host in your own context" I just need to face facts - I can't do what I want in pure PS. I have a alternate way of doing what I want through scheduling a Altiris job.

            – Minerbob
            Nov 19 '18 at 0:13














          0












          0








          0







          Remote call from PC-A to PB-B and PC-B needs to run a .exe on PC-C.



          Invoke-Command requires you be admin on whatever target you are trying to hit and that is only for that target.



          Are you saying you tried that last block of code and it failed?



          Because, if all remoting is configured properly, it should work this way.



          $PC_A = 'ws01'
          $PC_B = 'iis01'
          $cred = Get-Credential "$env:USERDOMAIN$env:USERNAME"

          "Running from $env:COMPUTERNAME"
          "Targetng $PC_A"
          Invoke-Command -ComputerName $PC_A -Credential $cred -ScriptBlock {
          "Targeting $Using:PC_B from $Using:PC_A via remote source"
          Invoke-Command -ComputerName $Using:PC_B -Credential $Using:cred -ScriptBlock {"PC_B name is $env:COMPUTERNAME"
          notepad.exe
          Get-Process -Name notepad
          }
          }

          # Results

          Running from DC01
          Targetng ws01
          Targeting iis01 from ws01 via remote source
          PC_B name is IIS01

          Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName PSComputerName
          ------- ------ ----- ----- ----- ------ -- ----------- --------------
          172 10 2184 9424 ...29 0.02 3520 notepad ws01


          You should also look at using PSDrive to the .exe on the second hop instead of the extra remote effort and running the .exe as if it was on the first hop.






          share|improve this answer















          Remote call from PC-A to PB-B and PC-B needs to run a .exe on PC-C.



          Invoke-Command requires you be admin on whatever target you are trying to hit and that is only for that target.



          Are you saying you tried that last block of code and it failed?



          Because, if all remoting is configured properly, it should work this way.



          $PC_A = 'ws01'
          $PC_B = 'iis01'
          $cred = Get-Credential "$env:USERDOMAIN$env:USERNAME"

          "Running from $env:COMPUTERNAME"
          "Targetng $PC_A"
          Invoke-Command -ComputerName $PC_A -Credential $cred -ScriptBlock {
          "Targeting $Using:PC_B from $Using:PC_A via remote source"
          Invoke-Command -ComputerName $Using:PC_B -Credential $Using:cred -ScriptBlock {"PC_B name is $env:COMPUTERNAME"
          notepad.exe
          Get-Process -Name notepad
          }
          }

          # Results

          Running from DC01
          Targetng ws01
          Targeting iis01 from ws01 via remote source
          PC_B name is IIS01

          Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName PSComputerName
          ------- ------ ----- ----- ----- ------ -- ----------- --------------
          172 10 2184 9424 ...29 0.02 3520 notepad ws01


          You should also look at using PSDrive to the .exe on the second hop instead of the extra remote effort and running the .exe as if it was on the first hop.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 16 '18 at 23:28

























          answered Nov 16 '18 at 23:18









          postanotepostanote

          3,4322410




          3,4322410













          • Remote call from PC-A to PB-B and PC-B needs to run a .exe on PC-C. Close....Remote call from PC-A to PB-B and PC-B needs to run a .exe Located on PC-C.

            – Minerbob
            Nov 18 '18 at 22:51













          • I get that and that is what I am showing in the sample. $env:computername (your PC-A) is the initial source to target PC-A (your PC-B), PC-A (your PC-B) is the source for PC-B ( your PC-C), executing notepad on PC-B (your PC-A), and that is a non-interactive thing. You can only run an app on any remote host in your own context, not the context of any user on a remote host. PS does not allow this, as it is a security boundary. If you want to run that app in the remote users context, the you have to use a 3rdP tool like psexec from sysinternals.

            – postanote
            Nov 18 '18 at 23:07











          • "You can only run an app on any remote host in your own context" I just need to face facts - I can't do what I want in pure PS. I have a alternate way of doing what I want through scheduling a Altiris job.

            – Minerbob
            Nov 19 '18 at 0:13



















          • Remote call from PC-A to PB-B and PC-B needs to run a .exe on PC-C. Close....Remote call from PC-A to PB-B and PC-B needs to run a .exe Located on PC-C.

            – Minerbob
            Nov 18 '18 at 22:51













          • I get that and that is what I am showing in the sample. $env:computername (your PC-A) is the initial source to target PC-A (your PC-B), PC-A (your PC-B) is the source for PC-B ( your PC-C), executing notepad on PC-B (your PC-A), and that is a non-interactive thing. You can only run an app on any remote host in your own context, not the context of any user on a remote host. PS does not allow this, as it is a security boundary. If you want to run that app in the remote users context, the you have to use a 3rdP tool like psexec from sysinternals.

            – postanote
            Nov 18 '18 at 23:07











          • "You can only run an app on any remote host in your own context" I just need to face facts - I can't do what I want in pure PS. I have a alternate way of doing what I want through scheduling a Altiris job.

            – Minerbob
            Nov 19 '18 at 0:13

















          Remote call from PC-A to PB-B and PC-B needs to run a .exe on PC-C. Close....Remote call from PC-A to PB-B and PC-B needs to run a .exe Located on PC-C.

          – Minerbob
          Nov 18 '18 at 22:51







          Remote call from PC-A to PB-B and PC-B needs to run a .exe on PC-C. Close....Remote call from PC-A to PB-B and PC-B needs to run a .exe Located on PC-C.

          – Minerbob
          Nov 18 '18 at 22:51















          I get that and that is what I am showing in the sample. $env:computername (your PC-A) is the initial source to target PC-A (your PC-B), PC-A (your PC-B) is the source for PC-B ( your PC-C), executing notepad on PC-B (your PC-A), and that is a non-interactive thing. You can only run an app on any remote host in your own context, not the context of any user on a remote host. PS does not allow this, as it is a security boundary. If you want to run that app in the remote users context, the you have to use a 3rdP tool like psexec from sysinternals.

          – postanote
          Nov 18 '18 at 23:07





          I get that and that is what I am showing in the sample. $env:computername (your PC-A) is the initial source to target PC-A (your PC-B), PC-A (your PC-B) is the source for PC-B ( your PC-C), executing notepad on PC-B (your PC-A), and that is a non-interactive thing. You can only run an app on any remote host in your own context, not the context of any user on a remote host. PS does not allow this, as it is a security boundary. If you want to run that app in the remote users context, the you have to use a 3rdP tool like psexec from sysinternals.

          – postanote
          Nov 18 '18 at 23:07













          "You can only run an app on any remote host in your own context" I just need to face facts - I can't do what I want in pure PS. I have a alternate way of doing what I want through scheduling a Altiris job.

          – Minerbob
          Nov 19 '18 at 0:13





          "You can only run an app on any remote host in your own context" I just need to face facts - I can't do what I want in pure PS. I have a alternate way of doing what I want through scheduling a Altiris job.

          – Minerbob
          Nov 19 '18 at 0:13


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53345710%2fpowershell-run-exe-on-remote-computer-using-a-unc-path-t%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Tangent Lines Diagram Along Smooth Curve

          Yusuf al-Mu'taman ibn Hud

          Zucchini