From 649e809d57efa53f4242c536ab62cea0768dd383 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Wed, 13 Dec 2023 16:53:52 -0800 Subject: [PATCH] Revert "Fix completion crash for the SCCM provider (#20815)" (#20919) --- .../CommandCompletion/CompletionCompleters.cs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs index 1f5c68fa31..357ce126ab 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs @@ -4764,20 +4764,17 @@ namespace System.Management.Automation // Save relevant info and try again to get just the names. foreach (dynamic child in childItemOutput) { - // TryAdd is used because some providers (like SCCM) may include duplicate PSPaths in a container. - _ = childrenInfoTable.TryAdd(GetChildNameFromPsObject(child, provider.ItemSeparator), child.PSIsContainer); + childrenInfoTable.Add(GetChildNameFromPsObject(child, provider.ItemSeparator), child.PSIsContainer); } _ = context.Helper.CurrentPowerShell .AddCommandWithPreferenceSetting("Microsoft.PowerShell.Management\\Get-ChildItem") .AddParameter("LiteralPath", pathInfo.Path) - .AddParameter("Name") - .AddCommandWithPreferenceSetting("Microsoft.PowerShell.Utility\\Sort-Object") - .AddParameter("Unique"); + .AddParameter("Name"); childItemOutput = context.Helper.ExecuteCurrentPowerShell(out _); - foreach (PSObject child in childItemOutput) + foreach (var child in childItemOutput) { - string childName = (string)child.BaseObject; + var childName = (string)child.BaseObject; childNameList.Add(childName); } } @@ -4786,12 +4783,8 @@ namespace System.Management.Automation foreach (dynamic child in childItemOutput) { var childName = GetChildNameFromPsObject(child, provider.ItemSeparator); - - // TryAdd is used because some providers (like SCCM) may include duplicate PSPaths in a container. - if (childrenInfoTable.TryAdd(childName, child.PSIsContainer)) - { - childNameList.Add(childName); - } + childrenInfoTable.Add(childName, child.PSIsContainer); + childNameList.Add(childName); } }