Skip to content

Is really PowerShell Direct tries to use PowerShell Core first? #7919

@stknohg

Description

@stknohg

Related #6669, #7241.

I tried to the following feature of Powershell Core 6.1 on Windows Server 2019 insider.

PowerShell Direct is a feature of PowerShell and Hyper-V that allows you to connect to a Hyper-V VM without network connectivity or other remote management services.

In the past, PowerShell Direct connected using the inbox Windows PowerShell instance on the VM.
Now, PowerShell Direct first attempts to connect using any available pwsh.exe on the PATH environment variable. If pwsh.exe isn't available, PowerShell Direct falls back to use powershell.exe.

But, PowerShell Direct for VM always uses Windows PowerShell.

Here is a simple PoC code.

PS C:\> Get-ComputerInfo -Property OsName, OsVersion

OsName                                   OsVersion
------                                   ---------
Microsoft Windows Server 2019 Datacenter 10.0.17744


PS C:\> $PSVersionTable.PSVersion

Major  Minor  Patch  PreReleaseLabel BuildLabel
-----  -----  -----  --------------- ----------
6      1      0

PS C:\> $cred = Get-Credential administrator

# PowerShell Dicret for VM always uses Windows PowerShell.
PS C:\> Invoke-Command -VMName TestVM -ScriptBlock { $PSVersionTable.PSVersion } -Credential $cred

Major  Minor  Build  Revision PSComputerName
-----  -----  -----  -------- --------------
5      1      14393  0        TestVM

Of course, PowerShell Core 6.1 is installed in the TestVM.
In addition, I can use PowerShell Core 6.1 with PowerShell Direct by specifying the -ConfigurationName parameter

# PowerShell Direct for VM uses PowerShell Core with -ConfigurationName parameter.
PS C:\> Invoke-Command -VMName TestVM -ScriptBlock { $PSVersionTable.PSVersion } -Credential $cred -ConfigurationName 'PowerShell.6'

Major  Minor  Patch  PreReleaseLabel BuildLabel  PSComputerName
-----  -----  -----  --------------- ----------  --------------
6      1      0                                  TestVM

I read #7241 and some source code.

I think that this feature applies only to PowerShell Direct for Container.
PowerShell Direct for VM uses Hyper-V Socket to communicate a VM.

Is my recognition correct?


Note: I also tried to this feature to a container, but I failed because of #5794.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-FixedThe issue is fixed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions