Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell - return custom object to C# host

I have the following powershell script which loads a custom .NET DLL this contains the ScriptResult class, it is intern executed from a VB.NET app.

Add-Type -Path $myLibPath

$result = New-Object TheLibrary.ScriptResult

In the VB.NET app I want to get the result object but the following doesnt seem to work

'get the script result
Dim result As ScriptResult = run.SessionStateProxy.GetVariable("result")

What am I not doing correctly?

like image 783
keyoke Avatar asked Jun 04 '26 06:06

keyoke


1 Answers

a) define the variable to the runtime first with

run.SessionStateProxy.SetVariable("result", null)

b) maybe could help to mark $result as global (not verified):

$global:result = New-Object TheLibrary.ScriptResult

like image 146
Tomas Panik Avatar answered Jun 07 '26 11:06

Tomas Panik