@@ -267,8 +267,13 @@ function Get-Keypress {
267267function Initialize-Module {
268268 param (
269269 [Parameter (Mandatory = $true )]
270- [String ] $Name
270+ [String ] $Name ,
271+ [Parameter (Mandatory = $false )]
272+ [String []] $Cmdlet ,
273+ [Parameter (Mandatory = $false )]
274+ [String []] $Function
271275 )
276+
272277 $NuGetVersion = (Get-PackageProvider ).Where ({ $_.Name -ceq ' NuGet' }).Version
273278 $installedModules = Get-Module - ListAvailable - Name $Name
274279
@@ -300,7 +305,11 @@ function Initialize-Module {
300305 # Verify the module is installed and present
301306 try {
302307 if (! (Get-Module - Name $Name )) {
303- Import-Module $Name
308+ $importParameters = @ {Name = $Name ; Scope = ' Local' } # Force the module to be imported into the local scope to avoid changing the global scope
309+ if ($PSBoundParameters.ContainsKey (' Cmdlet' )) { $importParameters [' Cmdlet' ] = $Cmdlet }
310+ if ($PSBoundParameters.ContainsKey (' Function' )) { $importParameters [' Function' ] = $Function }
311+
312+ Import-Module @importParameters
304313 }
305314 } catch {
306315 Write-Error " $Name was found in available modules, but could not be imported"
@@ -767,8 +776,8 @@ Initialize-ScriptRepository
767776
768777# ### Set up script dependencies
769778Initialize-Module - Name ' powershell-yaml' # Used for parsing YAML files
770- Initialize-Module - Name ' MSI' # Used for fetching MSI Properties
771- Initialize-Module - Name ' NtObjectManager' # Used for checking installer type inno
779+ Initialize-Module - Name ' MSI' - Cmdlet @ ( ' Get-MSITable ' ; ' Get-MSIProperty ' ) # Used for fetching MSI Properties
780+ Initialize-Module - Name ' NtObjectManager' - Function @ ( ' Get-Win32ModuleResource ' ; ' Get-Win32ModuleManifest ' ) # Used for checking installer type inno
772781# ### End of script dependencies
773782
774783# ### These variables are initialized late to prevent fetching file contents if -Help or -Settings was used
0 commit comments