cancel
Showing results for 
Search instead for 
Did you mean: 

call powershell script within shell execute

richard_pietsch
Active Contributor
0 Kudos

Hi all,

hope you can help me with this one as I am totally new to powershell...
I am trying to use a shell execute path with a "start script" A to call another powershell script B.
So, here is the command in IDM:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe A.ps1 -ADuser $FUNCTION.getADcredentials(LDAP_LOGIN)$$ -ADpw $FUNCTION.getADcredentials(LDAP_PASSWORD)$$ -Accountname $FUNCTION.getUserID(%MSKEY%)$$ -Accountpw $FUNCTION.getUserPW(%MSKEY%)$$


Within script A I create a credential object (for the user context script B is executed with):

$credentials = New-Object System.Management.Automation.PSCredential $ADuser,(ConvertTo-SecureString $ADpw -AsPlainText -Force)

The argument/parameter for script B is set:

$psscript = "\\host\idm$\B.ps1 -Username $Accountname -Passwort $Accountpw"

Then, I use a start-process command to execute script B:

$ps = Start-Process powershell -Credential $credentials -argument "$psscript" -PassThru

It does not work... BUT When I run script A with all the parameters in PowerShell application it is executed without issues, also I receive the transciption from script B. What is wrong here?

Regards, Richard


Accepted Solutions (0)

Answers (3)

Answers (3)

lambert-giese
Active Participant

"It does not work" could be a little more specific - but in case the problem is that the Shell Execute pass hangs, you may want to refer to brandon.a.bollin 's related problem and my suggestion.

richard_pietsch
Active Contributor
0 Kudos

Hi Lambert, I added some log outputs in the start script and here I see that the script is running. There is no exception or something like that. Even the start-process command appears to be executed. In the called script I activated the transcription but nothing is written into the log. So, from my point of view, script B is not executed at all when procssing the shell execute pass.

lambert-giese
Active Participant
0 Kudos

OK, in this case the other answer I linked is probably unrelated.

I'm not familar enough with Powershell to give any reliable advice here, but in case you're desperate, you could consider the following:

Usage of Start-Process itself might be a problem in a batch scenario. From what I read on StackOverflow, this would execute your second script B asynchronously in a new Window - this is probably not what you want and may not work at all in a server side batch scenario.

For one thing, asynchronous execution makes you unable to capture B's output from the calling script A. Moreover, it makes you lose control over how long B runs -any subsequent passes after ShellExecute would potentially start running with B still executing in parallel. Hence, I guess B should run synchronously, not asynchronously.

Maybe try adding the options -Wait and/or -NoNewWindow to Start-Process, or omit it completely as advised on SO.

richard_pietsch
Active Contributor
0 Kudos

Finally ^^

First, noticed that powershell does not like some special characters like & or ( ) when calling a script. Second, no need for the credential object if the separate dispatcher is running under the right useraccount *facepalm

alexanderbrietz
Active Contributor
0 Kudos

Hi Richard,

I am not a specialist with PowerShell. But the problem may be somewhere else.

Please keep in mind that the standard context calling the first script A is local system. AFAIK local system cannot access network drives and has different environment settings that may interfere with your procedure.

As a second point I would recommend to check all calls and parameters for file paths and verify whether they are all correct. Normally it would be a good idea to use full file paths in all such calls because you never know exactly where the command starts to be executed.

Third note: please keep in mind that your script is being executed on the runtime server where you run your dispatchers.

If this does not help try to run your scripts in the context you execute them actually. This would mean to generate a new dispatcher service and assign it your credentials to run this dispatcher and then run your job with this new dispatcher.

HTH

Regards,

Alex

richard_pietsch
Active Contributor
0 Kudos

Hi Alex,
as the "dialog" execution wih my logon user is working, I tried the following:
- created a new dispatcher service running with my logon user
- assigned the corresponding processes to this dispatcher
- test run

same result 😞

The start script is running, it executed the start-process cmd but script B is not called/executed.
KR, Richard

alexanderbrietz
Active Contributor
0 Kudos

Then you need to debug that with your means.

Try generating output to log, logging to file and add extra commands to see what happens. Default log is written to %$ddm.ddmpath%\DSE.log. I would also log the command you are trying to execute. Maybe you need to escape the backslashes or something...

Increase verbosity using your dispatcher and set log level to debug on the Java Runtime Engine. (Default is info like here in the screenshot)