2

I am using a C# library (.NET 4) with the System.Management.Automation DLL file to implement some commands for PowerShell (2.0).

I need to get a value from a command in a PowerShell script.

[Cmdlet(VerbsCommon.Get, "MyCommand")]
public class GetMyCommand : Cmdlet
{
    protected override void ProcessRecord()
    {
        // How do I return a value to PowerShell?
    }
}

The way I would like to get a value is something like this:

$value = Get-MyCommand
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131

1 Answers1

2

You have to use the CmdLet.WriteObject method.

Here is a good explanation from @RomanKuzmin.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
CB.
  • 58,865
  • 9
  • 159
  • 159