none
Unable to run an exe file on remote server through Invoke-Command. RRS feed

  • Question

  • I want to run an exe file on remote server through SQL Server Agent job's powershell command. This job is running successfully but it does not result in the execution of the exe file. I am able to execute this exe file using the testFile as the input argument by remote login

    $ErrorActionPreference = "Stop"
    Set-Location d:
    $OutputFile1= "\\server_name\ScheduledJobs\Prod\STM\testFile.txt"
    $STMExe="\\server_name\ScheduledJobs\Prod\STM\STM.exe "+$OutputFile1
    Invoke-Command -ComputerName server_name -ScriptBlock {$Args[0]} -args $STMExe
    • Moved by Bill_Stewart Monday, March 12, 2018 8:22 PM Unanswerable drive-by question
    Friday, January 19, 2018 11:00 PM

All replies

  • I have created a script which runs and sends sms as well. But when I am running the same script remotely on sql server its not sending the sms its showing as success but its not sending sms
    • Merged by Bill_Stewart Friday, January 19, 2018 11:25 PM Duplicate
    Friday, January 19, 2018 9:49 PM
  • We have no idea what you are talking about.  YOU have to provide accurate information.

    For SQLServer issue post in the SQLServer forum.


    \_(ツ)_/

    Friday, January 19, 2018 9:56 PM
  • You cannot remotely access a remote system from a remote command.  All files must reside on the remote system.


    \_(ツ)_/

    Friday, January 19, 2018 10:22 PM
  • I have all the files on the remote system and input file as well. BUt I am not getting sms though it say sucess
    Friday, January 19, 2018 10:30 PM
  • These two files are on a remote share:

    $OutputFile2= "\\XXX\yyy\SendTextMsg\"+$Date+"_sms.txt"

    $SendTextMsgExe=".\\XXX\yyy\SendTextMsg\SendTextMsg.exe $OutputFile2"

    They must be on a drive on the remote system.  You cannot access a share due to the second hop restriction in Windows.


    \_(ツ)_/

    Friday, January 19, 2018 10:35 PM
  • $ErrorActionPreference = "Stop"
    Set-Location g:

    $OutputFile1= "\\XXX\ScheduledJobs\yyy\SendTextMsg\testFile1.txt"
    $SendTextMsgExe="\\XXX\ScheduledJobs\yyy\SendTextMsg\SendTextMsg.exe "+$OutputFile1
    Invoke-Command -ComputerName XXX-ScriptBlock {$Args[0]} -args $SendTextMsgExe


    Now I cant even make this run thats using a test file1 already present on remote server
    Friday, January 19, 2018 10:45 PM
  • Last time I will say this.  You cannot use share paths remotely.  Use a path to the file that is local to the remote system.

    A local path looks like this "c:\test\file.txt".


    \_(ツ)_/

    Friday, January 19, 2018 11:27 PM