Skip to content

Get-Command -ListImported lists commands that weren't yet imported #28002

Description

Prerequisites

Steps to reproduce

We have an internal module, let's call it "TShell". It exports a command called "Open-Device".

If I run Get-Command Open-Device, then it will show me the command from the TShell module. If it hadn't been previously loaded, gcm triggered module auto-load, so TShell is always loaded afterward.

Hm, could I bypass this auto-load-during-query behavior? It seems like the -ListImported switch is exactly what I want--the documentation says it will "get only the commands in the current session."

But no: Get-Command Open-Device -ListImported still triggers TShell module auto-load.

(This also makes the -ListImported switch totally pointless: yeah, it only shows commands that are in the current session... but only because it already loaded them!)

Expected behavior

Don't trigger module auto-load when running `gcm -ListImported`.

Actual behavior

Modules get auto-loaded... so now the commands are imported (when they weren't before).

Error details

Environment data

Name                           Value
----                           -----
PSVersion                      7.6.5
PSEdition                      Core
GitCommitId                    7.6.5
OS                             Microsoft Windows 10.0.26687
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.4
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Activity

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

    Needs-TriageThe issue is new and needs to be triaged by a work group.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions