Skip to content

Windows PowerShell modules have a priority if WinCompat feature is enabled #11419

Closed

Description

@iSazonov

If WinCompat feature is enabled and loaded a Windows PowerShell module ,cmdlets from the module have a priority over PowerShell Core cmdlets.
/cc Andrew (@anmenaga)

Steps to reproduce

Get-Date -UFormat "%s" was changed in PowerShell Core and we use this in follow demo.

image

Expected behavior

Get-Date from PowerShell Core is involved.

I'd expect that PowerShell Core cmdlets have a priority or it is better WinCompat feature exports only requested cmdlet which explicitly presents in a feature list. Perhaps we could do Enable/Disable-WindowsPowerShellCmdlet -Module <name> -Cmdlet <name>

Actual behavior

Get-Date from Windows PowerShell is involved.

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.0-preview.6
PSEdition                      Core
GitCommitId                    7.0.0-preview.6-71-g36d3b3c0e45937d56650b2747effde94c20b42aa
OS                             Microsoft Windows 10.0.17763
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. anmenaga commented on Jan 14, 2020

    @anmenaga

    Yup, this is because proxy commands are Functions which precede Cmdlets during execution:

    If you do not specify a path, PowerShell uses the following precedence order when it runs commands:

    1. Alias
    2. Function
    3. Cmdlet
    4. Native Windows commands

    Enable/Disable-WindowsPowerShellCmdlet -Module <name> -Cmdlet <name is an interesting idea.

  2. doctordns commented on Jan 14, 2020

    @doctordns
    Collaborator

    Not convinced that Enable/Disable is needed. If you want fine-grained delegation, I'd suggest using JEA (once that starts to work properly in PowerShell 7).

  3. alexandair commented on Jan 14, 2020

    @alexandair
    Contributor

    Thomas Lee (@doctordns) What is a problem with JEA in PowerShell 7?

  4. SteveL-MSFT commented on Jan 14, 2020

    @SteveL-MSFT
    Member

    The user shouldn't have to manage the experience through enable/disable cmdlets. Ideally, if the cmdlet exists in PS7, that one should be used. However, we still want to support selective proxy generation so that ConvertFrom-String is available.

  5. doctordns commented on Jan 14, 2020

    @doctordns
    Collaborator

    Thomas Lee (@doctordns) What is a problem with JEA in PowerShell 7?

    In my case, it does not work properly in practice in RC1. See #11538

    It sounds like this is an issue, the team are aware of it, and it should be resolved by RTM (and hopefully earlier),

  6. anmenaga commented on Mar 5, 2020

    @anmenaga

    While the fix is being worked on, here is a temporary workaround that can be used:
    Local Core-native cmdlet can be called instead of the proxy function using call operator; e.g.:
    &(Get-Command -Name Import-Csv -CommandType Cmdlet) .\TestColumn.csv
    or

    $ImportCsv = Get-Command -Name Import-Csv -CommandType Cmdlet
    &($ImportCsv) .\TestColumn.csv
    
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

    ExperimentalExperimental FeatureIssue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions