Repository navigation
Description
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 -ListAvailablereturns a list of all files that are plausibly PowerShell modules (including those incompatible with the current PSEdition), ORGet-Module -ListAvailabledoes 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
daxian-dbw commentedon Jul 17, 2018
The related discussion from #7183 : #7183 (comment)
iSazonov commentedon Jul 20, 2018
/cc Michael Klement (@mklement0) What do you think?
mklement0 commentedon Jul 22, 2018
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:PSModulePathshould contain nothing but (well-formed) modules.Quietly including malformed modules in the
-ListAvailableresults seems unhelpful: you'll get no indication that something's wrong at the time of listing, only to encounter failure when you later try toImport-Module.iSazonov commentedon Jul 23, 2018
I believe we should have the same behavior for all paths and indicate that module (manifest) is broken. We could do this in
PSEditionfield. I think it looks better in interactive sessions. In scripts we can filter output if we need.mklement0 commentedon Jul 23, 2018
Ilya (@iSazonov): Just to clarify: You're suggesting not to report an error / warning, but instead to populate the
PSEditionproperty of theModuleInfoobjects representing malformed modules with a pseudo value that indicates the malformation?iSazonov commentedon Jul 24, 2018
Yes, in interactive session it looks better.
SteveL-MSFT commentedon Jul 24, 2018
If the module manifest is invalid, we shouldn't default to
Desktop.Desktopis only ifCompatiblePSEditionscontainsDesktopor ifCompatiblePSEditionsdoesn't exist at all (older module manifests pre-dating PS5). I think it would be fine to have???as thePSEditionvalue 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.mklement0 commentedon Jul 25, 2018
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:PSModulePaththat 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.PSEditionproperty 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).
iSazonov commentedon Jul 25, 2018
Michael Klement (@mklement0)
-ListAvailable Core(this can be default). I think it is better UX.mklement0 commentedon Jul 25, 2018
Ilya (@iSazonov)
An error is never pretty, but its job is to indicate an exceptional condition that needs attention.
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.
rjmholt commentedon Jul 25, 2018
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 generatedImport-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 anullresult fromLoadModuleManifestinGet-Module -ListAvailableotherwise 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.
mklement0 commentedon Jul 25, 2018
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:(With
$ErrorActionPreferenceat its default,Continue), the fact thathiprinted implies that the error is non-terminating.2 remaining items
SteveL-MSFT commentedon Jul 25, 2018
@PowerShell/powershell-committee reviewed this.
CompatiblePSEditionsis readable, but empty, it should default toDesktopexplicitly.Desktop.In the case a malformed module manifest is found, a non-terminating error should be returned.
mklement0 commentedon Jul 26, 2018
Thanks, Steve Lee (@SteveL-MSFT).
I have trouble reconciling the following two statements, however:
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
.CompatiblePSEditionsset 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?
SteveL-MSFT commentedon Jul 26, 2018
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.
rjmholt commentedon Jul 27, 2018
Steve Lee (@SteveL-MSFT) (& @PowerShell/powershell-committee), does
module manifest is invalidinclude 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)SteveL-MSFT commentedon Jul 27, 2018
Rob Holt (@rjmholt)
invalidmeans the module manifest is not well-formed. In the case where the module manifest is well-formed andCompatiblePSEditionsindicates 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 asDesktopif explicitly stated orDesktopifCompatiblePSEditionsis empty or doesn't exist.microsoft-github-policy-service commentedon Nov 16, 2023
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.
microsoft-github-policy-service commentedon Nov 16, 2023
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.
microsoft-github-policy-service commentedon Nov 16, 2023
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.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.