Skip to content

Function & Cmdlet Name Tab Completion Broken in the ConfigManager (CMSITE) Provider #20803

Closed

Description

Prerequisites

Steps to reproduce

Summary

7.4.0 seems to have broken cmdlet & function name tab completion for all cmdlet & functions while the location is set to the Config Manager provider (CMSITE). This was working just fine in previous versions of PowerShell 7.

Scope

  • Tab completion for cmdlet & function parameter names & values is not broken, even when the location is set to the CMSITE provider.
  • Cmdlet & Function name tab completion is not broken when the location is set to any of the built-in providers.
  • I can reproduce this on multiple machines.

Workaround

Reverting back to a previous version of PowerShell, i.e. 7.3.10, fixes the issue.

Background Info

My version of the ConfigurationManager module shouldn't matter since reverting back to PowerShell 7.3.10 fixes the issue, but just in case I am using version 5.2303.1089.1000 of the module.

Setup Code

PS C:\> Import-Module ConfigurationManager
PS C:\> $SiteCode = Get-PSDrive -PSProvider CMSITE
PS C:\> Set-Location -Path "$($SiteCode.Name):\"
PS DCC:\> Get-Ite{Tab}
PS DCC:\> function Test-TabCompletion {}
PS DCC:\> Test-TabCompletio{Tab}

Expected behavior

PS DCC:\> Get-Item
PS DCC:\> Test-TabCompletion

Actual behavior

PS DCC:\> Get-Ite
PS DCC:\> Test-TabCompletio

Error details

No response

Environment data

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

Visuals

No response

Activity

  1. MartinGC94 commented on Nov 28, 2023

    @MartinGC94
    Contributor

    It's probably related to the change I made here: #19489 I don't have any way to test tab completion in that provider though. Can you try to CD into that provider and run this: TabExpansion2 -inputScript Get- and post the full error details when it hopefully throws?

  2. alexlarner commented on Nov 28, 2023

    @alexlarner
    Author

    Here's the error details from that:

    PSMessageDetails      : 
    Exception             : System.Management.Automation.MethodInvocationException: Exception calling "CompleteInput" with "3" argument(s): "An item with the same key has already been added. Key: [Config Manager Primary FQDN Redacted]"
                             ---> System.ArgumentException: An item with the same key has already been added. Key: [Config Manager Primary FQDN Redacted]
                               at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
                               at CallSite.Target(Closure, CallSite, Dictionary`2, Object, Object)
                               at System.Management.Automation.CompletionCompleters.GetDefaultProviderResults(CompletionContext context, ProviderInfo provider, Collection`1 resolvedPaths, String filterText, Boolean containersOnly, Boolean relativePaths, Boolean literalPaths, Boolean inputUsedHome, String providerPrefix, StringConstantType stringType)
                               at System.Management.Automation.CompletionCompleters.CompleteFilename(CompletionContext context, Boolean containerOnly, HashSet`1 extension)
                               at System.Management.Automation.CompletionAnalysis.CompleteFileNameAsCommand(CompletionContext completionContext)
                               at System.Management.Automation.CompletionAnalysis.GetResultForIdentifier(CompletionContext completionContext, Int32& replacementIndex, Int32& replacementLength)
                               at System.Management.Automation.CompletionAnalysis.GetResultHelper(CompletionContext completionContext, Int32& replacementIndex, Int32& replacementLength)
                               at System.Management.Automation.CompletionAnalysis.GetResults(PowerShell powerShell, Int32& replacementIndex, Int32& replacementLength)
                               at System.Management.Automation.CommandCompletion.CompleteInputImpl(Ast ast, Token[] tokens, IScriptPosition positionOfCursor, Hashtable options)
                               at CallSite.Target(Closure, CallSite, Type, String, Int32, Hashtable)
                               --- End of inner exception stack trace ---
                               at System.Management.Automation.ExceptionHandlingOps.ConvertToMethodInvocationException(Exception exception, Type typeToThrow, String methodName, Int32 numArgs, MemberInfo memberInfo)
                               at CallSite.Target(Closure, CallSite, Type, String, Int32, Hashtable)
                               at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
                               at System.Management.Automation.Interpreter.DynamicInstruction`5.Run(InterpretedFrame frame)
                               at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
    TargetObject          : 
    CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    FullyQualifiedErrorId : ArgumentException
    ErrorDetails          : 
    InvocationInfo        : System.Management.Automation.InvocationInfo
    ScriptStackTrace      : at <ScriptBlock><End>, <No file>: line 40
                            at <ScriptBlock>, <No file>: line 1
    PipelineIterationInfo : {}
    
  3. MartinGC94 commented on Nov 28, 2023

    @MartinGC94
    Contributor

    Okay, it's probably failing here: https://github.com/PowerShell/PowerShell/blob/master/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs#L4786 because it's somehow finding 2 items with the same name in a folder/container.
    Can you run the following from that same location? ls -LiteralPath .\ | select -ExpandProperty PSPath and see if the same path shows up twice in the results?
    Also, can you run this: Get-PSProvider -PSProvider CMSITE | select -ExpandProperty ItemSeparator and validate that the reported item separator matches the one you see for each item in that list?
    Finally, can you tell me if it includes the provider name in the pspath results from before? Like: Microsoft.PowerShell.Core\FileSystem::C:\Users\Martin\.dotnet

  4. alexlarner commented on Nov 29, 2023

    @alexlarner
    Author
    1. ls -LiteralPath .\ | select -ExpandProperty PSPath
      • Returns 21 identical entries of AdminUI.PS\CMSite::[Config Manager Primary FQDN Redacted]\
    2. Get-PSProvider -PSProvider CMSITE | select -ExpandProperty ItemSeparator
      • Returns \
    3. Yes CMSITE is included in all the PSPath entries above
  5. MartinGC94 commented on Nov 29, 2023

    @MartinGC94
    Contributor

    Seems like the SCCM team misunderstood the purpose of the PSPath property in the provider system. The whole idea behind the provider system is that you can refer to objects by a path, similar to what you would do on a filesystem but obviously that can't work if the same path points to 21 different objects.
    It would have been nice if this had been enforced from the start but I guess that ship has sailed so we'll just have to handle their mistake by ignoring duplicates. I'll create a PR to fix this later today.

  6. alexlarner commented on Nov 29, 2023

    @alexlarner
    Author

    Thanks

  7. MartinGC94 commented on Nov 29, 2023

    @MartinGC94
    Contributor

    I've created the PR here: #20815 if you have the time feel free to download the Windows build that will get created as part of the automatic tests and then confirm that the changes I made actually fixed the issue for you.

  8. alexlarner commented on Dec 12, 2023

    @alexlarner
    Author

    I've created the PR here: #20815 if you have the time feel free to download the Windows build that will get created as part of the automatic tests and then confirm that the changes I made actually fixed the issue for you.

    Sorry, for the late response, but that didn't seem to fix it.

    And now when I try to run TabExpansion2 -inputScript Get-, I get this error instead.

    ErrorRecord                 : Exception calling "CompleteInput" with "3" argument(s): "StartIndex cannot be less than zero. (Parameter 'startIndex')"
    WasThrownFromThrowStatement : False
    TargetSite                  : Void ConvertToMethodInvocationException(System.Exception, System.Type, System.String, Int32, System.Reflection.MemberInfo)
    Message                     : Exception calling "CompleteInput" with "3" argument(s): "StartIndex cannot be less than zero. (Parameter 'startIndex')"
    Data                        : {}
    InnerException              : System.ArgumentOutOfRangeException: StartIndex cannot be less than zero. (Parameter 'startIndex')
                                     at System.String.Remove(Int32 startIndex)
                                     at System.Management.Automation.CompletionCompleters.GetDefaultProviderResults(CompletionContext context, ProviderInfo provider, Collection`1 resolvedPaths, String filterText, Boolean containersOnly,
                                  Boolean relativePaths, Boolean literalPaths, Boolean inputUsedHome, String providerPrefix, StringConstantType stringType) in
                                  D:\a\1\s\src\System.Management.Automation\engine\CommandCompletion\CompletionCompleters.cs:line 4820
                                     at System.Management.Automation.CompletionCompleters.CompleteFilename(CompletionContext context, Boolean containerOnly, HashSet`1 extension) in
                                  D:\a\1\s\src\System.Management.Automation\engine\CommandCompletion\CompletionCompleters.cs:line 4560
                                     at System.Management.Automation.CompletionAnalysis.CompleteFileNameAsCommand(CompletionContext completionContext) in
                                  D:\a\1\s\src\System.Management.Automation\engine\CommandCompletion\CompletionAnalysis.cs:line 2398
                                     at System.Management.Automation.CompletionAnalysis.GetResultForIdentifier(CompletionContext completionContext, Int32& replacementIndex, Int32& replacementLength) in
                                  D:\a\1\s\src\System.Management.Automation\engine\CommandCompletion\CompletionAnalysis.cs:line 2121
                                     at System.Management.Automation.CompletionAnalysis.GetResultHelper(CompletionContext completionContext, Int32& replacementIndex, Int32& replacementLength) in
                                  D:\a\1\s\src\System.Management.Automation\engine\CommandCompletion\CompletionAnalysis.cs:line 437
                                     at System.Management.Automation.CompletionAnalysis.GetResults(PowerShell powerShell, Int32& replacementIndex, Int32& replacementLength) in
                                  D:\a\1\s\src\System.Management.Automation\engine\CommandCompletion\CompletionAnalysis.cs:line 390
                                     at System.Management.Automation.CommandCompletion.CompleteInputImpl(Ast ast, Token[] tokens, IScriptPosition positionOfCursor, Hashtable options) in
                                  D:\a\1\s\src\System.Management.Automation\engine\CommandCompletion\CommandCompletion.cs:line 535
                                     at CallSite.Target(Closure, CallSite, Type, String, Int32, Hashtable)
    HelpLink                    :
    Source                      : System.Management.Automation
    HResult                     : -2146233087
    StackTrace                  :    at System.Management.Automation.ExceptionHandlingOps.ConvertToMethodInvocationException(Exception exception, Type typeToThrow, String methodName, Int32 numArgs, MemberInfo memberInfo) in
                                  D:\a\1\s\src\System.Management.Automation\engine\runtime\Operations\MiscOps.cs:line 2111
                                     at CallSite.Target(Closure, CallSite, Type, String, Int32, Hashtable)
                                     at <ScriptBlock><End>(Closure, FunctionContext)
    

    I believe I downloaded the right build. I downloaded this.

  9. MartinGC94 commented on Dec 13, 2023

    @MartinGC94
    Contributor

    Thanks. I've found a premade SCCM lab by MS that I can download and test this on. Will investigate and try to fix it in the near future.

  10. alexlarner commented on Dec 13, 2023

    @alexlarner
    Author

    Alex Larner (@alexlarner) You can download daily build from home page of the repository and if you still see the issue please report in #20803

    The repo home page Windows link takes you to a PowerShell-CI-windows pipeline, however there is also a PowerShell-CI-Windows-daily listed under Pipelines. I didn't know which of those you were referring to, so I attempted to test the latest of both.

    I was able to download and run PR-20913-20231212.03 from the PowerShell-CI-windows pipeline, and it had the same issue

    I couldn't get the latest two PowerShell-CI-Windows-daily builds to run as they were blocked from running by our company's Windows security.

  11. iambdud commented on Jul 17, 2024

    @iambdud

    I am still having this issue with 7.4.3. Was the change reverted?

  12. MartinGC94 commented on Jul 17, 2024

    @MartinGC94
    Contributor

    Looking at the 7.4 release branch, it doesn't seem like the fix has been added there: https://github.com/PowerShell/PowerShell/blob/release/v7.4/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs#L4858 so I guess they've forgotten to backport it (assuming they will do that since it was a regression).
    Hopefully they'll do that, but if not then I guess you'll just have to use 7.5

    GitHub
    PowerShell for every system! Contribute to PowerShell/PowerShell development by creating an account on GitHub.
  13. iambdud commented on Jul 17, 2024

    @iambdud

    Thanks for the reply. I am using 7.5 in the meantime.

    Sorry for my ignorance... but where did the fix go if it didn't make it into 7.4?

    Edit: Ahh. I see now. It was merged into master but did not make it into Release.

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

    In-PRIndicates that a PR is out for the issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions