Skip to content

Get-Module with a non-wildcard module name that doesn't match a loaded / available module quietly returns nothing #7498

@mklement0

Description

@mklement0

Follow-up from #7434 and related to #7521.

Note that this is a longstanding, albeit undocumented, behavior, and changing it now may break existing scripts, so there are two possible resolutions:

  • Conclude that changing this would break too many scripts and therefore make do with documenting the surprising / inconsistent behavior.

  • Conclude that this is a Bucket 3 change and make the change nonetheless.

Steps to reproduce

Ask for a nonexistent (loaded) module with a name that doesn't include wildcard characters:

Get-Module NoSuchModule

Expected behavior

A non-terminating error indicating the specified module isn't loaded.
$? should indicate $False

Analogously, with -ListAvailable, the error message should state that a module by that name isn't available (in any of the dirs. listed in $env:PSModulePath).

Actual behavior

Nothing ([System.Management.Automation.Internal.AutomationNull]::Value) is output, and $? reflects $True.

While this behavior may make sense for wildcard-based arguments, it doesn't for literal ones.

Compare this to the behavior of cmdlets such as Get-Item, Get-ChildItem, Get-Content, ..., which all fail if a given non-wildcard path doesn't identify an existing file.

Environment data

PowerShell Core v6.1.0-preview.4 on macOS 10.13.6
PowerShell Core v6.1.0-preview.4 on Ubuntu 16.04.4 LTS
PowerShell Core v6.1.0-preview.4 on Microsoft Windows 10 Pro (64-bit; Version 1803, OS Build: 17134.165)
Windows PowerShell v5.1.17134.165 on Microsoft Windows 10 Pro (64-bit; Version 1803, OS Build: 17134.165)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Breaking-Changebreaking change that may affect usersCommittee-ReviewedPS-Committee has reviewed this and made a decisionIssue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifWG-Cmdlets-Corecmdlets in the Microsoft.PowerShell.Core module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions