Remotely executing a program via a script

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

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

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

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

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