Error when using Microsoft.PowerShell.SDK 7.x from LINQPad

edited September 24

I'm using LINQPad to execute powershell commands. I've installed the 7.x version of the package (https://www.nuget.org/packages/Microsoft.PowerShell.SDK) and using this query (C# .NET 5.0)

using (PowerShell ps = PowerShell.Create())
    ps.AddScript("Import-Module Disk"); // This should not be necessary, because the module is loaded by default. 
    var result = ps.Invoke();

    Console.WriteLine(string.Join(";", result));        
    Console.WriteLine(string.Join(", ", ps.Streams.Error));

I'm getting this error.

Cannot process Cmdlet Definition XML for the following file: C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Storage\Disk.cdxml. Cannot convert the "Microsoft.Management.Infrastructure.CimInstance" value of type "System.String" to type "System.Type".

I don't know what's going on, because this very same code works in a .NET 5 Console application.
Thanks in advance!


Sign In or Register to comment.