6

I'm using a third-party module I found on GitHub and importing it with:

powershell Import-Module .\foo.ps1

This imports successfully and the module works great. But when I open a new PowerShell terminal, it doesn't load the module, I have to run the Import-Module command everytime. Is it possible to have modules load permanently?

I'm using Windows 10 with PowerShell v3.

vskbdvds
  • 163
  • 2
  • 2
  • 7
  • 6
    If you install the module correctly with [Install-Module](https://learn.microsoft.com/en-us/powershell/module/powershellget/install-module?view=powershell-5.1) it will be loaded automatically if needed – Olaf Jan 13 '19 at 22:49
  • 2
    Wow, that was super condescending and not at all helpful in any way. – vskbdvds Jan 13 '19 at 22:50
  • 1
    Since Powershell v3 Modules will be loaded automaticall if you install them to the right place with Install-Module. – Olaf Jan 13 '19 at 22:52
  • Alternatively you could place a `Import-Module .\foo.ps1` to your profile to make sure it's always loaded when you start a console. – Olaf Jan 13 '19 at 22:59
  • @Olaf the part about installing so that it resides in an auto-load location is helpful, would you post it as an answer? – briantist Jan 13 '19 at 23:06
  • 4
    @vskbdvds The comment is not condescending and is in fact helpful. – Bill_Stewart Jan 13 '19 at 23:50
  • @Bill_Stewart, Olaf quickly modified his comment after I said that. – vskbdvds Jan 14 '19 at 00:06
  • 1
    @vskbdvds in that case, you can delete your comment to reduce confusion. – Bill_Stewart Jan 14 '19 at 00:19
  • 1
    Just to make that completely clear - I only added "with Install-Module" including the link to my first comment!! – Olaf Jan 14 '19 at 07:16
  • Did you find an alternative solution? I'm having to use Import-Module in my profile for it to work. – Eloi Jan 13 '22 at 18:46

2 Answers2

8

You can add it to one of your profiles that powershell loads by default. Best bet is

%UserProfile%\My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 

or

%UserProfile%\My Documents\WindowsPowerShell\profile.ps1

see https://learn.microsoft.com/en-us/previous-versions//bb613488(v=vs.85) for the full list

Keith Nicholas
  • 43,549
  • 15
  • 93
  • 156
5

Since Powershell v3 Modules will be loaded automatically if you install them to the right place with Install-Module.

Here are additional information about installing Powershell modules: Installing a PowerShell Module

Olaf
  • 4,690
  • 2
  • 15
  • 23
  • what do you mean by the "right place"? why doesn't load automatically if I install with `Install-Module -Name MyModuleToInstall`. It only works for me if I use Import-Module before using the module commands. – Eloi Jan 13 '22 at 18:45
  • The module should be installed to a path listed in `$env:PSModulePath` to get loaded automatically. You can read more about here: [Get-Help about_PSModulePath](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_psmodulepath?view=powershell-7.2) – Olaf Jan 13 '22 at 19:06