This repository was archived by the owner on Jun 13, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
src/PowerShellGet/private/functions Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -46,15 +46,16 @@ function Validate-ModuleCommandAlreadyAvailable
46
46
if (-not $InstalledModuleInfo -or -not $InstalledModuleInfo.ModuleBase.StartsWith ($InstallLocation , [System.StringComparison ]::OrdinalIgnoreCase))
47
47
{
48
48
# Throw an error if there is a command with the same name from a different source.
49
- # Get-Command loads the module if a command is already available.
50
- # To avoid that, appending '*' at the end for each name then comparing the results.
51
49
$CommandNames = $CurrentModuleInfo.ExportedCommands.Values.Name
52
- $CommandNamesWithWildcards = $CommandNames | Microsoft.PowerShell.Core\Foreach-Object { " $_ *" }
53
50
54
- $AvailableCommands = Microsoft.PowerShell.Core\Get-Command - Name $CommandNamesWithWildcards `
51
+ # construct a hash with all of the commands in this module.
52
+ $CommandNameHash = @ {}
53
+ $CommandNames | % { $CommandNameHash [$_ ] = 1 }
54
+
55
+ $AvailableCommands = Microsoft.PowerShell.Core\Get-Command `
55
56
- ErrorAction Ignore `
56
57
- WarningAction SilentlyContinue |
57
- Microsoft.PowerShell.Core\Where-Object { ($CommandNames -contains $_.Name ) -and
58
+ Microsoft.PowerShell.Core\Where-Object { ($CommandNameHash .ContainsKey ( $_.Name ) ) -and
58
59
($_.ModuleName -ne $script :PSModuleProviderName ) -and
59
60
($_.ModuleName -ne ' PSModule' ) -and
60
61
($_.ModuleName -ne $CurrentModuleInfo.Name ) }
You can’t perform that action at this time.
0 commit comments