Return object from PowerShell using a parameter ("By Reference" parameter)? -


i have 1 powershell (2.0) script calling another. want receive not main output, additional object can use separately, e.g. display summary line in message.

let's have test2.ps1 script being called:

param([string]$summaryline) $issues = "potentially long list of issues" $summaryline = "37 issues found" $issues 

and test1.ps1 script calls it:

$mainoutput = & ".\test2.ps1" -summaryline $summaryoutput $mainoutput $summaryoutput 

the output simply:

potentially long list of issues 

although parameter $summaryline filled in test2, $summaryoutput remains undefined in test1.

defining $summaryoutput before calling test2 doesn't help; retains value assigned before calling test2.

i've tried setting $summaryoutput , $summaryline [ref] variables (as 1 can apparently functions), $summaryoutput.value property $null after calling test2.

is possible in powershell return value in parameter? if not, workarounds? directly assigning parent-scoped variable in test2?

ref should work, don't happened when tried it. here example:

test.ps1:

param ([ref]$optionaloutput)  "standard output" $optionaloutput.value = "optional output" 

run it:

$x = "" .\test.ps1 ([ref]$x) $x 

here alternative might better.

test.ps1:

param ($optionaloutput)  "standard output" if ($optionaloutput) {     $optionaloutput | add-member noteproperty summary "optional output" } 

run it:

$x = new-object psobject .\test.ps1 $x $x.summary 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -