Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Somehow Powershell kernel can't find any cmdlet #3665

Open
eosfor opened this issue Sep 9, 2024 · 3 comments
Open

Somehow Powershell kernel can't find any cmdlet #3665

eosfor opened this issue Sep 9, 2024 · 3 comments
Assignees
Labels
Area-Documentation Improvements or additions to documentation question Further information is requested

Comments

@eosfor
Copy link
Contributor

eosfor commented Sep 9, 2024

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 eosfor added the question Further information is requested label Sep 9, 2024
@jonsequitur
Copy link
Contributor

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

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

@eosfor
Copy link
Contributor Author

eosfor commented Sep 10, 2024

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

@jonsequitur
Copy link
Contributor

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

@jonsequitur jonsequitur added Area-Documentation Improvements or additions to documentation and removed waiting-on-feedback labels Sep 10, 2024
@jonsequitur jonsequitur self-assigned this Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Documentation Improvements or additions to documentation question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants