Forum Discussion

marika-9-5's avatar
marika-9-5
Copper Contributor
Nov 03, 2024
Solved

How do I permanently store module?

Hi everyone, I'm new to powershell, I would like to know how to automatically load the modules I load with import-module in each instance; if I load the modules with import-module, when I close the instance I lose the module. I would like to know how to permanently load, for example, the KPI module in the $Env:PsModulePath variable. Obviously the question is answered to all the modules that I always want to keep in section even when I start the computer. I hope for an answer

  • You don't need to load all modules to use cmdlets from it; when you first call a cmdlet, it will (in most cases) import the module for you at that moment. If not, you can run notepad $profile to open your Powershell profile and add a line import-module xyz to import it automatically in your future sessions.

     

    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_modules?view=powershell-7.4#module-autoloading

    • marika-9-5's avatar
      marika-9-5
      Copper Contributor
      thank you for your reply; yes it is actually useful and convenient to do so because you create your own script profiles and run them at the right time by loading modules in memory.

      However I always wonder if it is possible to do what I said, keeping in mind that I certainly prefer your solution to what I asked.

      However, out of curiosity I would like to know how to keep a fixed module at each system loading by inserting it in the variable $Env:PSModulePath.

      Then if there is no way to do it I will not insist

      I repeat at this point it is just a question of knowing whether it can be done or not, because I have already created the script in the profile.
      • Harm_Veenstra's avatar
        Harm_Veenstra
        MVP
        Install modules for AllUsers instead of CurrentUser (Install-Module xyz -Scope AllUsers)

Resources