Hosted PowerShell no puede ver Cmdlets en el mismo ensamblado
Estoy tratando de ejecutar scripts de PowerShell desde mi código C #, que usará Cmdlets personalizados del ensamblado que los ejecuta. Aquí está el código:
using System;
using System.Management.Automation;
[Cmdlet(VerbsCommon.Get,"Hello")]
public class GetHelloCommand:Cmdlet
{
protected override void EndProcessing()
{
WriteObject("Hello",true);
}
}
class MainClass
{
public static void Main(string[] args)
{
PowerShell powerShell=PowerShell.Create();
powerShell.AddCommand("Get-Hello");
foreach(string str in powerShell.AddCommand("Out-String").Invoke<string>())
Console.WriteLine(str);
}
}
Cuando intento ejecutarlo, obtengo una CommandNotFoundException. ¿Escribí mal mi Cmdlet? ¿Hay algo que deba hacer para registrar mi Cmdlet en PowerShell o en Runspace o algo así?