LINQPad7 unable import Powershell Hyper-V module to execute script

Let's say this code:

string _scr = ("Get-VM");
var _ps = PowerShell.Create();
Collection<PSObject> _cObj = _ps.Invoke();

if (_ps.HadErrors)

foreach (PSObject _vm in _cObj)

Is able to run in Visual Studio 2022 .NET Core 6.0 project (Install NuGet: Microsoft.PowerShell.SDK):

Also able to run in LINQPad 5(By reference another assembly(install NuGet: Microsoft.PowerShell.5.1.ReferenceAssemblies):

But confirmed unable to run in my latest LINQPad 7.4.2:(Install NuGet: Microsoft.PowerShell.SDK)

After investigation, this seems related to Import-Module, if we don't import any module, code will execute perfectly fine in LINQPad 7:

But code still unable to run in LINQPad 7 even if we write Import-Module Hyper-V.


Sign In or Register to comment.