Próbuję uruchomić skrypty PowerShell z mojego kodu C#, który użyje niestandardowych poleceń Cmdlets ze złożenia, który je uruchamia. Oto kod:Hostowany PowerShell nie widzi cmdletów w tym samym zestawie
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);
}
}
Kiedy próbuję go uruchomić, otrzymuję wyjątek CommandNotFoundException. Czy napisałem Cmdlet źle? Czy jest coś, co muszę zrobić, aby zarejestrować moje Cmdlet w PowerShell lub Runspace, czy coś w tym stylu?
Działa jak urok! dzięki! –