I started studying Powershell and was writing a module (psm1) in order to store my functions. Then I inserted this code in the module in order to reload the module when I modify it:
function reload
{
Remove-Module init
Import-Module F:\Script\init.psm1
}
The result of this function appears a little strange to me:
PS F:\Script> Get-Module
ModuleType Name ExportedCommands
---------- ---- ----------------
Script init {cpu, ie, lol, outlook...}
Manifest Microsoft.PowerShell.Management {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}
Manifest Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
PS F:\Script> reload
PS F:\Script> Get-Module
ModuleType Name ExportedCommands
---------- ---- ----------------
Manifest Microsoft.PowerShell.Management {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}
Manifest Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
PS F:\Script>
Why the second command in the function has no effect? I also noticed that the module appears in the list if I insert "Get-Module" at the end of my function, just like the module "runs" in an other Powershell instance/session. If so, is there a way to make the effects persistent?
Thank you!
EDIT:
I temporarily solved by adding a parameter to the import function in order to specify the scope in which to load the module:
Import-Module F:\Script\init.psm1 -Global
Is this the right way to deal with scope?
