Birdy
Birdy

Reputation: 1

call pwsh from powershell 5.1 and get return value only

My goal is to run a scriptblock with pwsh.exe and get just the return value from it.

$code = 'write-host 999 ; $a = @(1,2,3) ; return $a'

$sb = [ScriptBlock]::Create($code)

I'd like to see the original $a from the sciptblock here as a return value:

pwsh.exe $sb

But i get this array as a result:

999
999

1
2
3

What would be a solution to this problem?

Upvotes: 0

Views: 120

Answers (0)

Related Questions