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

.NET PowerShell runspace not auto-loading the Hyper-V Module when Hyper-V is enabled #2955

Open
bbonaby opened this issue May 17, 2024 · 1 comment
Assignees
Labels
Area-Environments Issue-Bug Something isn't working or needs investigation Priority-2

Comments

@bbonaby
Copy link
Contributor

bbonaby commented May 17, 2024

Dev Home version

No response

Windows build number

No response

Other software

No response

Steps to reproduce the bug

The Hyper-V extension requires that the Hyper-V PowerShell module be loaded into the PowerShell runspace before attempting to perform any Hyper-V functionality. If it is not loaded attempting to perform any operation will return an error.

When the Hyper-V PowerShell windows feature is enabled, it will be loaded into a users PowerShell runspace by default. In a However, for some machines it is not getting loaded into the runspace resulting in a similar error as below. The issue is only observed when interacting with PowerShell via the .Net PowerShellSDK in .Net 8. The issue does not happen on the same machine in a terminal powershell window. (Note: the below error occurred when navigating to the environment page for the first time after launching Dev Home):

System.Management.Automation.CommandNotFoundException: The 'Get-VM' command was found in the module 'Hyper-V', but the module could not be loaded. For more information, run 'Import-Module Hyper-V'.
at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection1 input, PSDataCollection1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection1 input, PSDataCollection1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
at HyperVExtension.Services.PowerShellService.ExecuteIndividualStatements(IEnumerable1 commandLineStatements, PipeType pipeType) at HyperVExtension.Services.PowerShellService.Execute(IEnumerable1 commandLineStatements, PipeType pipeType)

Another Note: Attempting to import the module results in the following error:
The module to process 'Microsoft.HyperV.PowerShell.Cmdlets.dll', listed in field 'NestedModules' of module manifest 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Hyper-V\2.0.0.0\Hyper-V.psd1' was not processed because no valid module was found in any module directory.

In the past I noticed this issue and added a workaround where we use the Get-Module -ListAvailable command as a way to force the the Hyper-V module to be loaded into the runspace, however this negatively affect perf. After reimaging my machine and enabling Hyper-V this error went away, so we removed the workaround. However, we have received at least one report for another user that they are encountering this error.

There are two things we can attempt to do to fix this:

  1. Re-add the work around that we know will work on most if not all PCs
  2. Find a different work around that does not negatively impact the perf of loading the Hyper-V VMs

Expected result

Hyper-V VMs load without errors

Actual result

Hyper-V VMs do not load and the user recieves the following error after navigating to the environments page without doing anything:
image

Included System Information

No response

Included Extensions Information

No response

@bbonaby bbonaby added Issue-Bug Something isn't working or needs investigation Area-Environments labels May 17, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Triage New issue that the core contributors need to triage label May 17, 2024
@kanismohammed kanismohammed added Priority-2 and removed Needs-Triage New issue that the core contributors need to triage labels May 20, 2024
@wn0x00
Copy link

wn0x00 commented May 30, 2024

how to do it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Environments Issue-Bug Something isn't working or needs investigation Priority-2
Projects
None yet
Development

No branches or pull requests

3 participants