Skip to content

Conversation

liamjpeters
Copy link
Contributor

@liamjpeters liamjpeters commented Aug 19, 2025

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

Copy link
Member

@andyleejordan andyleejordan left a 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.

@andyleejordan
Copy link
Member

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

@liamjpeters liamjpeters force-pushed the #2123CommandInfoCacheIssue branch from dc8786e to 8bde45d Compare October 14, 2025 09:15
@liamjpeters
Copy link
Contributor Author

My Git-Fu is not strong @andyleejordan 😅 Did I do it?

@andyleejordan
Copy link
Member

You did it! CI Tests are running now 😄

@andyleejordan andyleejordan enabled auto-merge (squash) October 14, 2025 16:30
@liamjpeters
Copy link
Contributor Author

If only it had succeeded. Drat.

The offending test that failed on the mac build runner:

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.

@andyleejordan
Copy link
Member

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

@andyleejordan andyleejordan merged commit 08bb38b into PowerShell:main Oct 14, 2025
5 of 7 checks passed
@liamjpeters liamjpeters deleted the #2123CommandInfoCacheIssue branch October 15, 2025 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

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

2 participants