interactive icon indicating copy to clipboard operation
interactive copied to clipboard

Somehow Powershell kernel can't find any cmdlet

Open eosfor opened this issue 1 year ago • 3 comments

I'm trying to make an extension for the .NET Interactive + Powershell Kernel. At this point i'm just trying to experiment, making a few tests. Looks like this:

    public OutTableTests()
    {
        var psKernel = new PowerShellKernel("powershell")
            .UseValueSharing();
        
        var csKernel = new CSharpKernel()
            .UseValueSharing()
            .UseWho();
        
        _kernel = new CompositeKernel
        {
            { psKernel, ["powershell"] },
            { csKernel, ["c#", "C#"] }
        };

        _kernel.DefaultKernelName = "powershell";


        //OutTableExtension.Load(_kernel);

        KernelEvents = _kernel.KernelEvents.ToSubscribedList();
    }

    public void Dispose()
    {
        _kernel.Dispose();
    }
    [Fact]
    public async Task BasicTest()
    {
        using var events = _kernel.KernelEvents.ToSubscribedList();

        //await _kernel.SendAsync(new SubmitCode("(Get-Process)[0] | Out-Table") );
        //var psModulePath = Environment.GetEnvironmentVariable(PSModulePathEnvName);
        
        await _kernel.SendAsync(new SubmitCode("$env:PSModulePath"));
        //await _kernel.FindKernelByName("powershell").SendAsync(new SubmitCode($"$env:PSModulePath = \"{psModulePath}\""));
        //await _kernel.SendAsync(new SubmitCode("Import-Module Microsoft.PowerShell.Management"));
        await _kernel.SendAsync(new SubmitCode("Get-ChildItem env:"));

        //await _kernel.FindKernelByName("powershell").SendAsync(new SubmitCode("dir env:"));
    }
}

However, somehow, after below is called,

await _kernel.SendAsync(new SubmitCode("Get-ChildItem env:"));

in the KernelEvents i see:

image

What do i do wrong?

Repo: https://github.com/eosfor/quickgraph-interactive/blob/experiments/OutTableExtension.Tests/OutTableTests.cs

eosfor avatar Sep 09 '24 09:09 eosfor

If you add this reference in your extension project, does it work as expected?

<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.4.3" />

jonsequitur avatar Sep 09 '24 19:09 jonsequitur

This seem worked, i'll doublecheck and close the issue

eosfor avatar Sep 10 '24 01:09 eosfor

Let's leave this open for the moment and document this. This is the second time I've seen someone hit this gotcha.

jonsequitur avatar Sep 10 '24 15:09 jonsequitur