<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: call powershell script within shell execute in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/call-powershell-script-within-shell-execute/qaa-p/12613043#M4730726</link>
    <description>&lt;P&gt;Hi Richard,&lt;/P&gt;&lt;P&gt;I am not a specialist with PowerShell. But the problem may be somewhere else.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Third note: please keep in mind that your script is being executed on the runtime server where you run your dispatchers.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;HTH&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Alex&lt;/P&gt;</description>
    <pubDate>Wed, 13 Jul 2022 14:51:44 GMT</pubDate>
    <dc:creator>alexanderbrietz</dc:creator>
    <dc:date>2022-07-13T14:51:44Z</dc:date>
    <item>
      <title>call powershell script within shell execute</title>
      <link>https://community.sap.com/t5/technology-q-a/call-powershell-script-within-shell-execute/qaq-p/12613042</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
  &lt;P&gt;hope you can help me with this one as I am totally new to powershell... &lt;BR /&gt;I am trying to use a shell execute path with a "start script" A to call another powershell script B.&lt;BR /&gt;So, here is the command in IDM:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;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%)$$&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;&lt;BR /&gt;Within script A I create a credential object (for the user context script B is executed with):&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;$credentials = New-Object System.Management.Automation.PSCredential $ADuser,(ConvertTo-SecureString $ADpw -AsPlainText -Force)&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;The argument/parameter for script B is set:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;$psscript = "\\host\idm$\B.ps1 -Username $Accountname -Passwort $Accountpw"
&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Then, I use a start-process command to execute script B:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;$ps = Start-Process powershell -Credential $credentials -argument "$psscript" -PassThru&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;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?&lt;/P&gt;
  &lt;P&gt;Regards, Richard&lt;/P&gt;
  &lt;BR /&gt;</description>
      <pubDate>Wed, 13 Jul 2022 10:24:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/call-powershell-script-within-shell-execute/qaq-p/12613042</guid>
      <dc:creator>richard_pietsch</dc:creator>
      <dc:date>2022-07-13T10:24:48Z</dc:date>
    </item>
    <item>
      <title>Re: call powershell script within shell execute</title>
      <link>https://community.sap.com/t5/technology-q-a/call-powershell-script-within-shell-execute/qaa-p/12613043#M4730726</link>
      <description>&lt;P&gt;Hi Richard,&lt;/P&gt;&lt;P&gt;I am not a specialist with PowerShell. But the problem may be somewhere else.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Third note: please keep in mind that your script is being executed on the runtime server where you run your dispatchers.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;HTH&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Alex&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2022 14:51:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/call-powershell-script-within-shell-execute/qaa-p/12613043#M4730726</guid>
      <dc:creator>alexanderbrietz</dc:creator>
      <dc:date>2022-07-13T14:51:44Z</dc:date>
    </item>
    <item>
      <title>Re: call powershell script within shell execute</title>
      <link>https://community.sap.com/t5/technology-q-a/call-powershell-script-within-shell-execute/qaa-p/12613044#M4730727</link>
      <description>&lt;P&gt;"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  &lt;SPAN class="mention-scrubbed"&gt;brandon.a.bollin&lt;/SPAN&gt; 's related problem and my &lt;A href="https://answers.sap.com/answers/292938/view.html"&gt;suggestion&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2022 16:08:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/call-powershell-script-within-shell-execute/qaa-p/12613044#M4730727</guid>
      <dc:creator>lambert-giese</dc:creator>
      <dc:date>2022-07-13T16:08:51Z</dc:date>
    </item>
    <item>
      <title>Re: call powershell script within shell execute</title>
      <link>https://community.sap.com/t5/technology-q-a/call-powershell-script-within-shell-execute/qaa-p/12613045#M4730728</link>
      <description>&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 06:48:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/call-powershell-script-within-shell-execute/qaa-p/12613045#M4730728</guid>
      <dc:creator>richard_pietsch</dc:creator>
      <dc:date>2022-07-14T06:48:45Z</dc:date>
    </item>
    <item>
      <title>Re: call powershell script within shell execute</title>
      <link>https://community.sap.com/t5/technology-q-a/call-powershell-script-within-shell-execute/qaa-p/12613046#M4730729</link>
      <description>&lt;P&gt;Hi Alex, &lt;BR /&gt;as the "dialog" execution wih my logon user is working, I tried the following:&lt;BR /&gt;- created a new dispatcher service running with my logon user &lt;BR /&gt;- assigned the corresponding processes to this dispatcher&lt;BR /&gt;- test run&lt;/P&gt;&lt;P&gt;same result &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The start script is running, it executed the start-process cmd but script B is not called/executed.&lt;BR /&gt;KR, Richard&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 06:52:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/call-powershell-script-within-shell-execute/qaa-p/12613046#M4730729</guid>
      <dc:creator>richard_pietsch</dc:creator>
      <dc:date>2022-07-14T06:52:20Z</dc:date>
    </item>
    <item>
      <title>Re: call powershell script within shell execute</title>
      <link>https://community.sap.com/t5/technology-q-a/call-powershell-script-within-shell-execute/qaa-p/12613047#M4730730</link>
      <description>&lt;P&gt;Then you need to debug that with your means.&lt;/P&gt;&lt;P&gt;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...&lt;/P&gt;&lt;P&gt;Increase verbosity using your dispatcher and set log level to debug on the Java Runtime Engine. (Default is info like here in the screenshot)&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2073454-grafik.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 09:46:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/call-powershell-script-within-shell-execute/qaa-p/12613047#M4730730</guid>
      <dc:creator>alexanderbrietz</dc:creator>
      <dc:date>2022-07-14T09:46:45Z</dc:date>
    </item>
    <item>
      <title>Re: call powershell script within shell execute</title>
      <link>https://community.sap.com/t5/technology-q-a/call-powershell-script-within-shell-execute/qaa-p/12613048#M4730731</link>
      <description>&lt;P&gt;OK, in this case the other answer I linked is probably unrelated.&lt;/P&gt;&lt;P&gt;I'm not familar enough with Powershell to give any reliable advice here, but in case you're desperate, you could consider the following:&lt;/P&gt;&lt;P&gt;Usage of &lt;STRONG&gt;Start-Process&lt;/STRONG&gt; itself might be a problem in a batch scenario. From what I read on &lt;A href="https://stackoverflow.com/a/51334633/2478870"&gt;StackOverflow&lt;/A&gt;, this would execute your second script B &lt;STRONG&gt;asynchronously&lt;/STRONG&gt; in a new Window - this is probably not what you want and may not work at all in a server side batch scenario. &lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Maybe try adding the options -Wait and/or -NoNewWindow to Start-Process, or omit it completely as advised on SO.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 10:03:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/call-powershell-script-within-shell-execute/qaa-p/12613048#M4730731</guid>
      <dc:creator>lambert-giese</dc:creator>
      <dc:date>2022-07-14T10:03:54Z</dc:date>
    </item>
    <item>
      <title>Re: call powershell script within shell execute</title>
      <link>https://community.sap.com/t5/technology-q-a/call-powershell-script-within-shell-execute/qaa-p/12613049#M4730732</link>
      <description>&lt;P&gt;Finally ^^&lt;/P&gt;&lt;P&gt;First, noticed that powershell does not like some special characters like &amp;amp; or ( ) when calling a script. Second, no need for the credential object if the separate dispatcher is running under the right useraccount *facepalm&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 10:47:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/call-powershell-script-within-shell-execute/qaa-p/12613049#M4730732</guid>
      <dc:creator>richard_pietsch</dc:creator>
      <dc:date>2022-07-14T10:47:27Z</dc:date>
    </item>
  </channel>
</rss>

