GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Change CommandInfo lookup for commands in the form `module\cmdletName` by liamjpeters · Pull Request #2125 · PowerShell/PSScriptAnalyzer

Conversation

@liamjpeters

@liamjpeters Liam Peters (liamjpeters) commented Aug 19, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

PR Summary

When the CommandInfoCache is used to lookup some fully qualified commands (by way of Get-Command), a nested module name is returned.

PR changes CommandInfoCache when a CommandInfo is looked up for a command in the form module\cmdletName. It passes this module name hint along to Get-Command to allow correct resolution.

With the MicrosoftTeams module installed, as an example, running:

Get-Command -Name 'MicrosoftTeams\Get-CsOnlineLisCivicAddress'

Reports the commands module as Microsoft.Teams.ConfigAPI.Cmdlets.

Instead running:

Get-Command -Name 'Get-CsOnlineLisCivicAddress' -Module 'MicrosoftTeams'

Correctly reports the module as MicrosoftTeams.

Also happens for Az.resources\Get-AzRoleEligibilitySchedule

Fixes #2123
Fixes #2023

PR Checklist

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Change is not breaking
  • Make sure all .cs, .ps1 and .psm1 files have the correct copyright header
  • Make sure you've added a new test if existing tests do not effectively test the code changed and/or updated documentation
  • This PR is ready to merge and is not Work in Progress.
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@liamjpeters
Liam Peters (liamjpeters) requested review from Andy Jordan (andyleejordan) and Christoph Bergmeister (bergmeister) as code owners August 19, 2025 22:45
andyleejordan
Andy Jordan (andyleejordan) approved these changes Oct 13, 2025
View reviewed changes

@andyleejordan Andy Jordan (andyleejordan) left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thanks so much! Weird, seems like there may be a bug in Get-Command itself because that behavior is changing between the module-qualified command name, and passing the module name as a separate parameter. Maybe a sorting issue, we don't know. This is a good workaround given your tests.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@andyleejordan

Andy Jordan (andyleejordan) commented Oct 13, 2025

Copy link
Copy Markdown
Member

Liam Peters (@liamjpeters) can you rebase this so the PR checks trigger and I can merge it? Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@liamjpeters
Change how looking up CommandInfo works when using commands in the fo…
8bde45d
…rm module\cmdletName
@liamjpeters
Liam Peters (liamjpeters) force-pushed the #2123CommandInfoCacheIssue branch from dc8786e to 8bde45d Compare October 14, 2025 09:15
@liamjpeters

Liam Peters (liamjpeters) commented Oct 14, 2025

Copy link
Copy Markdown
Contributor Author

My Git-Fu is not strong Andy Jordan (@andyleejordan) 😅 Did I do it?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andyleejordan

Andy Jordan (andyleejordan) commented Oct 14, 2025

Copy link
Copy Markdown
Member

You did it! CI Tests are running now 😄

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andyleejordan
Andy Jordan (andyleejordan) enabled auto-merge (squash) October 14, 2025 16:30
@liamjpeters

Liam Peters (liamjpeters) commented Oct 14, 2025

Copy link
Copy Markdown
Contributor Author

If only it had succeeded. Drat.

The offending test that failed on the mac build runner:

PSScriptAnalyzer/Tests/Rules/UseCorrectCasing.tests.ps1

Lines 77 to 85 in ea70855

It "Does not throw when correcting certain cmdlets (issue 1516)" {
$scriptDefinition = 'Get-Content;Test-Path;Get-ChildItem;Get-Content;Test-Path;Get-ChildItem'
$settings = @{ 'Rules' = @{ 'PSUseCorrectCasing' = @{ 'Enable' = $true; CheckCommands = $true; CheckKeywords = $true; CheckOperators = $true } } }
{
1..100 |
ForEach-Object { $null = Invoke-ScriptAnalyzer -ScriptDefinition $scriptDefinition -Settings $settings -ErrorAction Stop }
} |
Should -Not -Throw
}

I don't have a mac to try it on, but the failure looks like the runspace safety issue with the command info cache - an old discussion and summary in issue #1867.

I've run the test in a loop and managed to get it to fail once with the same error on my Windows machine after about 20 mins of running. I've managed the same on the master branch just now:

image

I'm not sure how to check whether this PR makes this issue more prevalent or if it's the same as it has been and just got unlucky with the CI run.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andyleejordan

Andy Jordan (andyleejordan) commented Oct 14, 2025

Copy link
Copy Markdown
Member

That seems like it's a flaky test, I'm rerunning the CI.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andyleejordan
Andy Jordan (andyleejordan) merged commit 08bb38b into PowerShell:main Oct 14, 2025
@liamjpeters
Liam Peters (liamjpeters) deleted the #2123CommandInfoCacheIssue branch October 15, 2025 08:01
@jessehouwing Jesse Houwing (jessehouwing) mentioned this pull request Aug 19, 2026
On github actions ubuntu-latest analysis fails with "The term 'Get-Command' is not recognized as a name of a cmdlet" #2205
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@bergmeister Christoph Bergmeister (bergmeister) Awaiting requested review from bergmeister bergmeister is a code owner
1 more reviewer
@andyleejordan Andy Jordan (andyleejordan) andyleejordan approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Code Formatter: Don't remove module names from cmdlet calls UseCorrectCasing removes <module>\ from <module>\<cmdlet> in vscode-powershell

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@liamjpeters @andyleejordan
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.