Skip to content

Get-Module -ListAvailable hides edition-incompatible modules but lists otherwise incompatible modules #7298

Closed

Description

@rjmholt

Get-Module -ListAvailable will list modules with badly formatted manifests or that have unmet requirements, but will not list modules that have incompatible PSEditions (as per the RFC).

Get-Module -ListAvailable should be consistent about whether modules that can be loaded in a current session can be listed.

Here's a small repro for an unloadable module that is still listed by Get-Module -ListAvailable:

> New-Item -Path $PowerShellDevDir\src\powershell-win-core\bin\Debug\netcoreapp2.1\win7-x64\publish\Modules\BADMODULE -Value "Banana"

> Get-Module -ListAvailable
...

    Directory:
    C:\users\roholt\documents\dev\powershell\src\powershell-win-core\bin\debug\netcoreapp2.1\win7-x64\publish\Modules


ModuleType Version    Name                                PSEdition ExportedCommands
---------- -------    ----                                --------- ----------------
Manifest   6.1.0.0    CimCmdlets                          Core      {Get-CimAssociatedInstance, Get-CimClass, Get-CimInst...
Script     0.0        LocalUnsignedModule                 Desk
Script     0.0        LocalUntrustedModule                Desk
Manifest   1.1.0.0    Microsoft.PowerShell.Archive        Desk      {Compress-Archive, Expand-Archive}
Manifest   6.1.0.0    Microsoft.PowerShell.Diagnostics    Core      {Get-WinEvent, New-WinEvent}
Manifest   6.1.0.0    Microsoft.PowerShell.Host           Core      {Start-Transcript, Stop-Transcript}
Manifest   6.1.0.0    Microsoft.PowerShell.Management     Core      {Add-Content, Clear-Content, Clear-ItemProperty, Join...
Manifest   6.1.0.0    Microsoft.PowerShell.Security       Core      {Get-Acl, Set-Acl, Get-PfxCertificate, Get-Credential...
Manifest   6.1.0.0    Microsoft.PowerShell.Utility        Core      {Format-List, Format-Custom, Format-Table, Format-Wid...
Manifest   6.1.0.0    Microsoft.WSMan.Management          Core      {Disable-WSManCredSSP, Enable-WSManCredSSP, Get-WSMan...
Manifest   0.0        BADMODULE                           Desk
Script     1.1.7.0    PackageManagement                   Desk      {Find-Package, Get-Package, Get-PackageProvider, Get-...
Script     4.2.0      Pester                              Desk      {Describe, Context, It, Should...}
Script     1.6.0      PowerShellGet                       Desk      {Install-Module, Find-Module, Save-Module, Update-Mod...
Script     0.0        PSDesiredStateConfiguration         Desk      {Test-ModuleReloadRequired, ConvertTo-MOFInstance, In...
Script     6.1.0.0    PSDiagnostics                       Core      {Disable-PSTrace, Disable-PSWSManCombinedTrace, Disab...
Script     2.0.0      PSReadLine                          Desk      {Get-PSReadLineKeyHandler, Set-PSReadLineKeyHandler, ...
Binary     1.1.1      ThreadJob                           Desk      Start-ThreadJob

Essentially, you can write a nonsense module in a file with the right extension, and if it's on the module path, it will be displayed by Get-Module -ListAvailable. But a psd1 that is correct but does not list "Core" under "CompatiblePSEditions" will not be displayed.

A consequence of this is that if a module is not compatible with the current PSEdition and loaded from the System32 module path, but has another error in it that causes the manifest processing to fail earlier, the module will be listed when the CompatiblePSEditions RFC says it should not be.

One proposal might be, either:

  • Get-Module -ListAvailable returns a list of all files that are plausibly PowerShell modules (including those incompatible with the current PSEdition), OR
  • Get-Module -ListAvailable does not list modules that are unable to be loaded in the current PowerShell session (this would be a more significant breaking change).
> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.1.0-preview.3
PSEdition                      Core
GitCommitId                    v6.1.0-preview.3-161-g6d72598bde08ca2507cd357b5723204ec4941541
OS                             Microsoft Windows 10.0.17713
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. added
    Issue-Discussion
    on Jul 16, 2018
  2. daxian-dbw commented on Jul 17, 2018

    @daxian-dbw
    Member

    The related discussion from #7183 : #7183 (comment)

  3. iSazonov commented on Jul 20, 2018

    @iSazonov
    Collaborator

    /cc Michael Klement (@mklement0) What do you think?

  4. mklement0 commented on Jul 22, 2018

    @mklement0
    Contributor

    I'm late to this and may not have the full picture, but just in the abstract it sounds like it's worth either reporting a non-terminating error or at least a warning for every malformed module, given that it's fair to assume that locations in $env:PSModulePath should contain nothing but (well-formed) modules.

    Quietly including malformed modules in the -ListAvailable results seems unhelpful: you'll get no indication that something's wrong at the time of listing, only to encounter failure when you later try to Import-Module.

  5. iSazonov commented on Jul 23, 2018

    @iSazonov
    Collaborator

    I believe we should have the same behavior for all paths and indicate that module (manifest) is broken. We could do this in PSEdition field. I think it looks better in interactive sessions. In scripts we can filter output if we need.

  6. mklement0 commented on Jul 23, 2018

    @mklement0
    Contributor

    Ilya (@iSazonov): Just to clarify: You're suggesting not to report an error / warning, but instead to populate the PSEdition property of the ModuleInfo objects representing malformed modules with a pseudo value that indicates the malformation?

  7. iSazonov commented on Jul 24, 2018

    @iSazonov
    Collaborator

    Yes, in interactive session it looks better.

  8. SteveL-MSFT commented on Jul 24, 2018

    @SteveL-MSFT
    Member

    If the module manifest is invalid, we shouldn't default to Desktop. Desktop is only if CompatiblePSEditions contains Desktop or if CompatiblePSEditions doesn't exist at all (older module manifests pre-dating PS5). I think it would be fine to have ??? as the PSEdition value when an invalid module manifest is encountered. I'm also ok with a non-terminating error is this is likely going to only occur as a development scenario.

  9. mklement0 commented on Jul 25, 2018

    @mklement0
    Contributor

    Steve Lee (@SteveL-MSFT): Agreed on not defaulting to Desktop.

    As for what to do instead: the question comes down to how we defined an available module:

    • (a) Anything that happens to be present in a dir. listed in $env:PSModulePath, whether it is a well-formed module or not.

    • (b) Something that's present in in a dir. listed in $env:PSModulePath that is also a well-formed module (though it may not be available to the platform at hand).

    If (a), then perhaps reporting malformed modules as part of the success output with ??? as the .PSEdition property makes sense.

    If (b), then malformed modules should be reported as non-terminating errors.


    Personally I'm not convinced that (a) makes sense:

    Ilya (@iSazonov): Can you elaborate on why you think that how things look in an interactive session should be the driving factor?

    Granted, how PowerShell currently surfaces errors can be characterized as "scary, noisy, lengthy information overload" - see #3647 - but that's a separate issue (the resolution of which is way overdue, by the way).

  10. iSazonov commented on Jul 25, 2018

    @iSazonov
    Collaborator

    Michael Klement (@mklement0)

    1. Displaying the table is corrupted by error messages
    2. We must be consistent - if we display incompatible modules, then we must show the broken modules. If we want get only "core" compatible modules we need a filer like -ListAvailable Core (this can be default). I think it is better UX.
  11. added
    Review - Committee
    on Jul 25, 2018
  12. mklement0 commented on Jul 25, 2018

    @mklement0
    Contributor

    Ilya (@iSazonov)

    1. Displaying the table is corrupted by error messages

    An error is never pretty, but its job is to indicate an exceptional condition that needs attention.

    1. We must be consistent - if we display incompatible modules, then we must show the broken modules

    A malformed (broken) module is not an incompatible module. You cannot meaningfully classify a malformed module beyond its "brokenness" - that is why it should be treated as an exception.

  13. rjmholt commented on Jul 25, 2018

    @rjmholt
    CollaboratorAuthor

    I think one point worth mentioning is that for a module with an invalid manifest (e.g. malformed manifest, wrong PowerShell version, missing required module, etc.), you get the following behaviours:

    • Get-Module -ListAvailable: Module appears -- a "fake" PSModuleInfo is generated
    • Import-Module: An error is thrown (I think terminating, but not certain)

    Whereas, for a module with the wrong edition loaded from the System32 path:

    • Get-Module -ListAvailable: Module does not appear -- it effectively does not exist (I had to introduce an unpleasant hack to make this behaviour happen, since a null result from LoadModuleManifest in Get-Module -ListAvailable otherwise gets turned into the fake PSModuleInfo)
    • Import-Module: An error is thrown, just like in the above scenario.

    Having the edition check use special behaviour seems a bit inconsistent to me, but more importantly, introduces complexity that we will need to continue to maintain forever.

  14. mklement0 commented on Jul 25, 2018

    @mklement0
    Contributor

    Rob Holt (@rjmholt): Not knowing the internals and possibly missing part of the picture, here's what makes sense to me:

    • Get-Module -ListAvailable ... list all (well-formed) edition-compatible modules.

    • Get-Module -ListAvailable -SkipEditionCheck ... list all (well-formed) available modules, including edition-incompatible ones.

    Irrespective of the specific parameters, any malformed module should generate a non-terminating error.

    Re Import-Module: the error it reports with a malformed module is non-terminating, which is consistent with PowerShell's guidelines in general (it accepts an array of modules to import) - though debatable in this specific case.


    As an aside: An easy way to test if a command generates a terminating or non-terminating error, using the example of Import-Module (assume the presence of an invalid manifest at ./badModule/badModule.psd1:

    PS> 'hi' -f (Import-Module ./badModule)
    Import-Module : The module manifest '...' could not be processed because it is not a valid PowerShell module manifest file
    hi

    (With $ErrorActionPreference at its default, Continue), the fact that hi printed implies that the error is non-terminating.

  15. 2 remaining items

  16. SteveL-MSFT commented on Jul 25, 2018

    @SteveL-MSFT
    Member

    @PowerShell/powershell-committee reviewed this.

    • If CompatiblePSEditions is readable, but empty, it should default to Desktop explicitly.
    • If it can't read the module manifest, then that value should be an empty string and not Desktop.

    In the case a malformed module manifest is found, a non-terminating error should be returned.

  17. mklement0 commented on Jul 26, 2018

    @mklement0
    Contributor

    Thanks, Steve Lee (@SteveL-MSFT).

    I have trouble reconciling the following two statements, however:

    1. If it can't read the module manifest, then that value should be an empty string and not Desktop.
    2. In the case a malformed module manifest is found, a non-terminating error should be returned.

    This makes it sound like a malformed module should both (1) output a dummy module-info object as part of the success output stream with .CompatiblePSEditions set to '' and (2) return a non-terminating error to indicate the malformation.

    However, my expectation is that (2) is sufficient - what benefit is there in also reporting a malformed module as part of the success output?

  18. SteveL-MSFT commented on Jul 26, 2018

    @SteveL-MSFT
    Member

    Michael Klement (@mklement0) I think when I typed up the summary we were still in discussion between showing PSEdition as empty (and some other indicator it is invalid) or producing a non-terminating error. We ended up with agreeing that a non-terminating error makes the most sense (with expectation that we improve the visual of non-terminating errors which is already another issue).

    So to summarize, @PowerShell/powershell-committee agreed on throwing a non-terminating error if the module manifest is invalid.

  19. rjmholt commented on Jul 27, 2018

    @rjmholt
    CollaboratorAuthor

    Steve Lee (@SteveL-MSFT) (& @PowerShell/powershell-committee), does module manifest is invalid include or exclude modules that rejected because of an incompatible PSEdition? (I assume exclude, but code-wise, the edition check is one of the validity checks and will require special handling)

  20. SteveL-MSFT commented on Jul 27, 2018

    @SteveL-MSFT
    Member

    Rob Holt (@rjmholt) invalid means the module manifest is not well-formed. In the case where the module manifest is well-formed and CompatiblePSEditions indicates it is not compatible, that is still a valid module manifest and should follow existing behavior which is it doesn't show up (if under system32 path) without -SkipEditionCheck, otherwise, it should show as Desktop if explicitly stated or Desktop if CompatiblePSEditions is empty or doesn't exist.

  21. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  22. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  23. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  24. added
    Resolution-No Activity
    on Nov 16, 2023
  25. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

  26. added
    WG-Cmdlets
    and removed on Jul 17, 2026
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

    Breaking-ChangeIssue-DiscussionResolution-No ActivityWG-Cmdlets

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions