I have one PowerShell (2.0) script calling another. I want to get back not only the main output, but also an additional object that I can use separately, for example. to display the summary line in the message.
Let Test2.ps1 be as the called script:
param([String]$SummaryLine) $Issues = "Potentially long list of issues" $SummaryLine = "37 issues found" $Issues
And Test1.ps1 as a script that calls it:
$MainOutput = & ".\Test2.ps1" -SummaryLine $SummaryOutput $MainOutput $SummaryOutput
The result is simple:
Potentially long list of issues
Although the $ SummaryLine parameter is populated with Test2, the $ SummaryOutput remains undefined in Test1.
Defining $ SummaryOutput before calling Test2 does not help; it just saves the value assigned before calling Test2.
I tried setting $ SummaryOutput and $ SummaryLine as [ref] variables (as you can do with functions), but the $ SummaryOutput.Value property is $ null after calling Test2.
Is it possible in PowerShell to return a value to a parameter? If not, what are the workarounds? Directly assign a variable with parent scope in Test2?
Mark berry
source share