Powershell - return custom object to C# host Powershell - return custom object to C# host powershell powershell

Powershell - return custom object to C# host


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


GetVariable returns a PSVariable instance. The variable's value is in the .Value property. You'll probably need to cast it (DirectCast) to your ScriptResult type as Value returns an Object.