PowerShell / PowerShell/PowerShell

Get-Module -ListAvailable doesn't respect DefaultPrefix

Open
#15,743 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

In-PR Needs-Triage WG-Engine-Module
Dominant language
C#
Stars
55.5k
Forks
8.5k
Avg merge
1d 2h
Merged PRs (30d)
88

Description

Prerequisites
Steps to reproduce

Use any module that has the DefaultCommandPrefix defined in the module manifest. I modified one of my modules to test with.

In Windows PowerShell, if I have a module that uses a defined prefix, this works as expected.

Expected behavior
PS C:\> $mod = Get-Module PSChristmas -ListAvailable
PS C:\> $mod.ExportedFunctions.keys
New-xElfName
Get-xPSChristmasPresent
New-xPSChristmasGreeting
New-xPSChristmas
Show-xPSChristmasMessage
Invoke-xJingle
Write-xFestive

The module is NOT loaded into my session. But not in PowerShell 7. PowerShell 7 fails to use the prefix.

Actual behavior
PS C:\> $mod = Get-Module PSChristmas -ListAvailable
PS C:\> $mod.ExportedFunctions.keys
New-ElfName
Get-PSChristmasPresent
New-PSChristmasGreeting
New-PSChristmas
Show-PSChristmasMessage
Invoke-Jingle
Write-Festive

If I import the module in PowerShell 7 and re-run the command then it works.

PS C:\> import-module pschristmas
PS C:\> $mod = Get-Module PSChristmas
PS C:\> $mod.ExportedFunctions.keys
Get-xPSChristmasPresent
Invoke-xJingle
New-xElfName
New-xPSChristmas
New-xPSChristmasGreeting
Show-xPSChristmasMessage
Write-xFestive 
Environment data
Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Microsoft Windows 10.0.19043
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Also tested in 7.2.0-preview.4 with the same results.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with a module manifest that defines DefaultCommandPrefix, then compare Get-Module -ListAvailable with the behavior after Import-Module. Trace how exported functions are populated for the list-available path. Done means the listed exported function names include the manifest prefix before the module is imported.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.