cancel
Showing results for 
Search instead for 
Did you mean: 

uShellRead function - read output of script on windows - IdM 7.2

Former Member
0 Kudos

Hi!

Has anyone experience with the uShellRead IdM-function? It should be able to execute a script and read the output. Has anyone done that on windows yet? I am trying to execute a powershell script and read its output. Background is trying to integrate MS Exchange with IdM.

Thanks,

Raphael

Accepted Solutions (0)

Answers (6)

Answers (6)

Former Member
0 Kudos

I'm am using a dispatcher installed on a separate machine. Also the powershell script is on a separate machine. Could that have any influence?

Former Member
0 Kudos

I solved the powershell calls using this (like Peter Wass suggested):

  • uShell instead of uShellRead (=> fire and forget)
  • Adding | out-file to every relevant line in the powershell commands, thus writing in one or more files (depending on what I want to log)
  • Adding a task as result handling (on OK) and checking the errors from the file and further steps like mailing the admin or logging in the job
Former Member
0 Kudos

Good to hear you got it working. If this is part of a workflow you want to make sure each entry processed has its own output file. If not you risk another entry getting processed and overwriting the content of your output file before the ONOK task has the chance to process it during load situations.

As a member of the IdM development team I had to test some more to try to find out what could be wrong 🙂

I just tested this a couple of times. First using CMD:

12.12.2013 10:44:34 :I:Shell function 'cmd /C echo BOB' terminated with exit code 0

12.12.2013 10:44:34 :I:Shell function output: BOB

12.12.2013 10:44:34 :I:BOB

Then using powershell:

12.12.2013 10:48:12 :I:Shell function 'powershell -Command echo BOB' terminated with exit code 0

12.12.2013 10:48:12 :I:Shell function output: BOB

12.12.2013 10:48:12 :I:BOB

And as you see they both work fine. However, when testing with a file "C:\temp\ps.ps1" to run the output was not picked up:

12.12.2013 10:55:44 :I:Shell function 'powershell C:empps.ps1' terminated with exit code 0

12.12.2013 10:55:49 :I:To Generic pass completed in 5.896 seconds.

It didnt hang like in your situation though. When I changed it to C:/temp/ps.ps1 it worked again:

12.12.2013 10:56:51 :I:Shell function 'powershell C:/temp/ps.ps1' terminated with exit code 0

12.12.2013 10:56:51 :I:Shell function output: BOB

Not sure what conclusions to make of this yet though.

Br,

Per Christian

Message was edited by: Per Krabsetsve

Former Member
0 Kudos

How did you configure the job, what passes did you use to test this? Where did you linked the script, e.g. source-tab, destination-tab? I dont know what is the right way to call a script..

Thanks and regards,

Raphael

Former Member
0 Kudos

Hi,

I used to To Generic pass, picture uploader seems still to be broken... Destination looks something like this:

Open destination: Empty

Next data entry: testShell

Close destination: Empty

MSKEY %MSKEY%

OTHERPARAM %OTHERPARAM%

With this script (not using the parameters for anything, but included for demo-purpose):

function testShell(Par){

  //Result = uShellRead("cmd /C echo BOB",0);

  mskey = Par.get("MSKEY");

  otherparam = Par.get("OTHERPARAM");

  Result = uShellRead("powershell C:/temp/ps.ps1",0);

   uInfo(Result);

  return;

}

In the script you can set the result in a context variables for example and use it in a conditional to decide to send notification or not, or other stuff.

Br,

Per Chrisrtian

Former Member
0 Kudos

Looks like its treating '\' as an escape rather than an actual part of the file path.  Its probably logical given that \ is usually to escape things in LDAP etc.  Changing the path to / is a good start (although counter-intuitive for windows users).

I see to remember that there was a problem I had with executing powershell commands.

I think I used cmd /c powershell.exe script.ps1 as the command, rather then just running powershell directly.  Otherwise it appeared to hang while running powershell...

Peter

terovirta
Active Contributor
0 Kudos

Peter Wass wrote:

Looks like its treating '\' as an escape rather than an actual part of the file path.  Its probably logical given that \ is usually to escape things in LDAP etc.  Changing the path to / is a good start (although counter-intuitive for windows users).

Did you try escaping the escape character; "\\" instead of '\'..

Former Member
0 Kudos

Yes, \ is treated as escape character, and both / and \\ work fine as replacements but thats not what troubled me. I can't reproduce the powershell hang situation that Raphael reported using any combination of /, \, \\, the -Command option, cmd /C or CMD without /C 🙂

So far the only conclusion I have is that when using single \ in the path the script was not executed and nothing was returned, but it did not hang. So it seems that everything is fine in our code, which is good. But it may not be of help to the original poster.

Br,

Per Christian

Former Member
0 Kudos

I had it on SP7 - and a few other people on the forums have had it too.

Actually, I've had similar problems with 'Write-Host' in powershell.  If that command is in, it can sometimes hang.  Try getting rid of any (or adding them to reproduce).

Peter

Former Member
0 Kudos

What possibilities do I have to develop my own "powershell connector"? Assuming I don't want to use the standard functionality?

Thx,

Raphael

Former Member
0 Kudos

What do you mean with exact scenario?

I just want to execute a script and read its output. If I execute a powershell script i want to be able to pass in some parameters and read the output, e.g. if the execution was successfull. Exchange integration is done just by executing powershell scripts.

I dont want the output to be written to a file, this is a hack. I am trying to execute something like this: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe H:\powershell\createNewMailbox.ps1 Parameter1 Parameter 2 Parameter 3.

When I am executing the command above the job gets a time out. Either with uShellRead or with a ShellExecute Pass...

Regards,

Raphael

Former Member
0 Kudos

To answer the actual question with something useful instead of my previous attempt...

Try running the dispatcher in testmode to see if its an authorization issue. It could be that when started as a local system, which the dispatcher uses as default, its not allowed to execute the powershell. It could be throwing up one of those popup-dialogs that you're unable to see unless you check the "allow service to interract with desktop" option in services. I ask this because I'm sure you've tested your commandline manually with your login and it works perfectly fine, but when IdM tries to run it it does not.

Br,

Per Christian

keith_zhang
Active Participant
0 Kudos

Hello Raphael,

Have you also tried/tested the exchange server provisioning, integrated in the create AD user plugin task of SAP provisioning framework? Here is the link to the repository constants:

http://help.sap.com/saphelp_nwidmic_72/helpdata/en/d8/032660e11849978a2ba2675b5dd719/content.htm?fra...

BR, Keith

Former Member
0 Kudos

I haven't used it I'm afraid.  Exchange integration can always be a pain.

Have you considered just writing the powershell output to a file and reading the data with the next job?  As per Matt, it depends on the exact scenario you're trying to achieve.

What results are you getting?  Is it executing but not reading the output, or not executing at all.  You'll also need to make sure the service account you're running the dispatcher as has the rights to use the Exchange powershell features, rights in exchange and probably a few other things on the server.

Peter

former_member2987
Active Contributor
0 Kudos

Raphael,

No I have not.  What is your exact scenario?  I assume for some reason the SAP documentation on the topic isn't a good fit for you?

Regards,

Matt