Skip to content

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

Closed

Description

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.

Activity

  1. added
    Issue-Question
    on Oct 2, 2018
  2. SteveL-MSFT commented on Oct 5, 2018

    @SteveL-MSFT
    Member

    Takuya Shibata (@stknohg) this is a doc issue. Looking at the original code change, this only affects creating a PSSession to a Container. Submitted doc fix.

    However, since we've standardized the ConfigurationName for PSCore6, we could change the VM path to try PowerShell.6 first then fallback to Microsoft.PowerShell (which defaults to Windows PowerShell)

  3. stknohg commented on Oct 7, 2018

    @stknohg
    ContributorAuthor

    Steve Lee (@SteveL-MSFT)
    Thank you for clarifying. I understood.
    I will close this Issue after the document is updated.


    However, since we've standardized the ConfigurationName for PSCore6, we could change the VM path to try PowerShell.6 first then fallback to Microsoft.PowerShell (which defaults to Windows PowerShell)

    Good idea.
    However, I think we should discuss how to try and fallback when newer versions (e.g. PowerShell Core 7.0) come out.
    We can discuss after it becomes necessary.

  4. SteveL-MSFT commented on Oct 8, 2018

    @SteveL-MSFT
    Member

    Closing this issue as the doc change got merged. Please open a new issue if we want to consider trying different sessionconfigurations for VMs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-QuestionResolution-Fixed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions