@Show PowerShell não pode ver os Cmdlets no mesmo Assembly
Estou tentando executar scripts do PowerShell a partir do meu código C #, que usará Cmdlets personalizados do assembly que os executa. Aqui está o 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);
}
}
Quando tento executá-lo, recebo uma CommandNotFoundException. Eu escrevi meu Cmdlet errado? Há algo que preciso fazer para registrar meu cmdlet no PowerShell ou no Runspace ou algo assim?