on ‎2022 Jul 13 11:24 AM
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
Help others by sharing your knowledge.
AnswerRequest clarification before answering.
"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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.
| User | Count |
|---|---|
| 15 | |
| 9 | |
| 6 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.