Remotely executing a program via a script

Tagged: 

This topic contains 4 replies, has 3 voices, and was last updated by Profile photo of Sergiu-Andrei Creifelean Sergiu-Andrei Creifelean 3 months, 2 weeks ago.

  • Author
    Posts
  • #54908
    Profile photo of Andy Tuke
    Andy Tuke
    Participant

    Hi all,

    I have written a script which generates an argument set for an IBM application called Cognos which produces data cubes. My script produces a set of strings in the format –
    -nologo -n -c -g -f'\\dfsnamespace-Path\Preferences.xml' -m'\\dfsnamespace-Path\PPC005.mdl'

    The unc paths are abstracted by DFS in Active Directory.

    I am testing this on my workstation, the final plan will be for it to run on a clustered scheduling 2012 Server, and the final action is to create a remote session to the Cognos application server which will then run the command line generated. So my script creates a variable $CommandLineArgs containing a string like the one above

    If I run the following in the shell it works (the Cogtr.exe executable has been added to the Path Environment variable on the app server)

    $CommandLineArgs = "-nologo -n -c -g -f'\\dfsnamespace-Path\Preferences.xml' -m'\\dfsnamespace-Path\PPC005.mdl'"
    Enter-PSSession -ComputerName PPCLive01.mydomain.co.uk -Credential $Cred -Authentication Credssp
        Invoke-Expression ("Cogtr.exe "+ $CommandLineArgs)
    Exit-PSSession
    

    But if I put exactly the same lines of code in a script then I get the error, I have tried putting the full path

    Cogtr.exe : The term 'Cogtr.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    At line:1 char:1

    Any help would be enormously appreciated. I am assuming that the script is not attempting to run the Cogtr.exe on the server, but on my Workstation.
    Thanks

    Andy

    • This topic was modified 3 months, 2 weeks ago by Profile photo of Andy Tuke Andy Tuke.
    • This topic was modified 3 months, 2 weeks ago by Profile photo of Andy Tuke Andy Tuke.
    • This topic was modified 3 months, 2 weeks ago by Profile photo of Andy Tuke Andy Tuke.
  • #54916

    Hi Andy,
    Try specifying the full path name to Cogtr.exe and if this fails try to use "Cogtr.exe " -join $CommandLineArgs
    Regards,
    Sergiu

    • #54920
      Profile photo of Andy Tuke
      Andy Tuke
      Participant

      Hi Sergiu,

      Already tried that. I don't think its trying to run the expression on the remote server, but on my workstation which doesn't have the Cogtr.exe installed. I'm also trying to get it to work with Invoke-Command, something like

      $MyArgs1 = "-nologo -n -c -g -f'\\dfsnamespace-Path\Preferences.xml' -m'\\dfsnamespace-Path\PPC005.mdl'"
      $Session = New-PSSession -ComputerName PPCLive01.domain.co.uk -Credential $Cred -Authentication Credssp
          Invoke-Command -Session $Session -ScriptBlock {param ([string]$arguments); Cogtr.exe $arguments} -ArgumentList $MyArgs1 -asjob
      Remove-PSSession $Session
      
      • This reply was modified 3 months, 2 weeks ago by Profile photo of Andy Tuke Andy Tuke.
      • This reply was modified 3 months, 2 weeks ago by Profile photo of Andy Tuke Andy Tuke.
  • #54951
    Profile photo of Max Kozlov
    Max Kozlov
    Participant

    if you want to ensure your code run on remote side you may try to output `$env:ComputerName`

    $Session = New-PSSession -ComputerName PPCLive01.domain.co.uk -Credential $Cred -Authentication Credssp
        Invoke-Command -Session $Session -ScriptBlock { $env:ComputerName } -asjob
    Remove-PSSession $Session
    

    You also can do directory listing

    • This reply was modified 3 months, 2 weeks ago by Profile photo of Max Kozlov Max Kozlov.
  • #54953

    Hi Andy,
    Try the following:

    $MyArgs1 = "-nologo -n -c -g -f'\\dfsnamespace-Path\Preferences.xml' -m'\\dfsnamespace-Path\PPC005.mdl'"
    $Session = New-PSSession -ComputerName PPCLive01.domain.co.uk -Credential $Cred -Authentication Credssp
    Enter-PSSession -Session $Session
    Start-Process "PathToFile\Cotgr.exe " -join $MyArgs1
    Exit-PSSession

    Regards,
    Sergiu

You must be logged in to reply to this topic.