Skip to content

Commit 7daac2e

Browse files
Refactor Import-PSModule to validate module existence using imported commands
1 parent f811cca commit 7daac2e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

scripts/helpers/Import-PSModule.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@
3838
$availableModules = Get-Module -ListAvailable -Refresh -Verbose:$false
3939
$availableModules | Select-Object Name, Version, Path | Sort-Object Name | Format-Table -AutoSize
4040
Write-Host ' - List commands'
41+
$commands = Get-Command -Module $moduleName -ListImported
4142
Write-Host (Get-Command -Module $moduleName -ListImported | Format-Table -AutoSize | Out-String)
4243

43-
if ($moduleName -notin $availableModules.Name) {
44+
if ($moduleName -notin $commands.Source) {
4445
throw 'Module not found'
4546
}
4647
}

0 commit comments

Comments
 (0)