Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Commit f54e2ec

Browse files
committed
slightly simpler approach
1 parent a101843 commit f54e2ec

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/PowerShellGet/private/functions/Validate-ModuleCommandAlreadyAvailable.ps1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,14 @@ function Validate-ModuleCommandAlreadyAvailable
5050
# To avoid that, appending '*' at the end for each name then comparing the results.
5151
$CommandNames = $CurrentModuleInfo.ExportedCommands.Values.Name
5252

53-
# construct a regex matching any of the commands in this module.
54-
$Matcher = [regex](($CommandNames | % { "($_)" }) -join "|")
53+
# construct a hash with all of the commands in this module.
54+
$CommandNameHash = @{}
55+
$CommandNames | % { $CommandNameHash[$_] = 1 }
5556

5657
$AvailableCommands = Microsoft.PowerShell.Core\Get-Command -Name * `
5758
-ErrorAction Ignore `
5859
-WarningAction SilentlyContinue |
59-
Microsoft.PowerShell.Core\Where-Object { ($Matcher.IsMatch($_.Name)) -and
60+
Microsoft.PowerShell.Core\Where-Object { ($CommandNameHash.ContainsKey($_.Name)) -and
6061
($_.ModuleName -ne $script:PSModuleProviderName) -and
6162
($_.ModuleName -ne 'PSModule') -and
6263
($_.ModuleName -ne $CurrentModuleInfo.Name) }

0 commit comments

Comments
 (0)