Powershell: Get return result from Powershell Script called from Within other PS Script Powershell: Get return result from Powershell Script called from Within other PS Script powershell powershell

Powershell: Get return result from Powershell Script called from Within other PS Script


Any uncaptured output is returned in Powershell.

So something like

return $returnRollBackObj

is equivalent to

$returnRollBackObjreturn

So, since script2 is returning these objects, as long as these objects are not captured in script1, they will be returned by script1 as well. So you not have to do anything about "returning undefined number of objects"

Try running the scripts from console first, to see if you are getting the intended behaviour.


How's your IIS setup?

Just thinking , if you hve eimpersonation on, tha it might not have access to the second script's location due to the double hop issue.

Something else that may help is the transcript functionality. Add a start-transcript at the top of yu script/code and you'll get a dump of everything, comands and output (inc. Errors and warnings).

Edit:

Just realised your not assigning the returned values from script2 to aaything in script1.

You may need something like this:

$ret = & $script2 ...

Do something with $ret...

OR put it in an array$ret = @()

For loop...

$temp = & $script2 ...$ret = $ret + $temp

Then return $ret after the for loop.

Matt