I have a script I want to use interactively from a PowerShell prompt. The script should use the local script module.
I do not see how to import / use the module so that it does not remain loaded in the current session.
Example
Module (MyModule.psm1) ...
function Test-Method { write-host "Test-Method invoked" }
... and a script (script.ps1)
Import-Module .\MyModule Test-Method
Now run the script at the PowerShell prompt ...
PS C:\temp> Get-Module | % {$_.Name} Microsoft.PowerShell.Management Microsoft.PowerShell.Utility PS C:\temp> .\script.ps1 Test-Method invoked PS C:\temp> Get-Module | % {$_.Name} Microsoft.PowerShell.Management Microsoft.PowerShell.Utility MyModule
How can my script import and use MyModule.psm1 without loading it into the current call session? Considering that the call may have already imported the module and would not like to unload it using the script (therefore, simply removing the module upon completion of the script is not very good).
I thought that instead of importing it, instead of importing it, I want the module to be dot-sourcing, but I need the module for the reasons described in PowerShell Import-Module vs Dot Sourcing
source share