Update to 5.1 breaks Get-WindowsFeature when Carbon module is installed

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 2 months, 3 weeks ago.

  • Author
    Posts
  • #65205
    Profile photo of Matt McElreath
    Matt McElreath
    Participant

    I've been testing WMF 5.1 recently and noticed a random issue. After installing WMF 5.1 I could no longer run Get-WindowsFeature. I get the following error:

    PS C:\> Get-WindowsFeature
    Get-WindowsFeature : The term 'Get-WindowsFeature' is not recognized as the name of a cmdlet, function, script file,
    or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and
    try again.
    At line:1 char:1
    + Get-WindowsFeature
    + ~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (Get-WindowsFeature:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

    Tab complete still works for the cmdlet however. After some digging, I figured out that the issue happens because we have the Carbon module installed (https://www.powershellgallery.com/packages/Carbon/2.4.1) which is utilized by our DSC configuration. If I explicitly run Import-Module Servermanager, Get-WindowsFeature works fine. When I delete Carbon from the server, the Get-WindowsFeature cmdlet works without any issues.

    It worked fine with WMF 5.0. It only breaks when 5.1 is installed. I did notice that Carbon has a function in its Functions folder called Get-WindowsFeature.ps1. That function is also listed in the module manifest under "FunctionsToExport". If I remove Get-WindowsFeature from FunctionsToExport, the Get-WindowsFeature cmdlet works again.

    I'm wondering why this module would work fine under WMF 5.0 but breaks now under 5.1. I can remove Get-WindowsFeature from FunctionsToExport as a temporary fix but I'd rather not rely on that long term since we don't maintain that module. Has anyone else seen an issue like this?

  • #65388
    Profile photo of Don Jones
    Don Jones
    Keymaster

    You might report this on the PowerShell GitHub repo as an issue, or on the UserVoice page. But it's very likely a naming collision on your system – if you've got two things exporting the same function/command name, it's going to use the last-one-in when you try to run the command. Honestly, Carbon shouldn't be using Get-WindowsFeature as a name – you might mention this to that author, first.

You must be logged in to reply to this topic.