Just like Bash on Linux, PowerShell on Windows has it’s PATH-like variable from which modules are being automatically loaded. To find out array of your paths you can use:
PS C:\Users\ivant> $env:PSModulePath
D:\Ivan\Documents\PowerShell\Modules;C:\Program Files\PowerShell\Modules;c:\program files\powershell\7\Modules;C:\Progra
m Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules
Now, I have already experimented a bit with PowerShell but I’ve used Windows PowerShell (different version than Core) and I’ve written a module for it which I’d very much like to continue using in PowerShell Core as well.
I know it perhaps isn’t the wisest idea to mix modules like that, but serves my purpose. I could have easily copied module to PowerShell path instead.
In order to persistently load that additional path where my Windows PowerShell modules are located I had to first find a path where should I define it. In my case it was PROFILE file was located:
PS C:\Users\ivant> $PROFILE
D:\Ivan\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
Now, in order to override the provided one, I used:
$env:PSModulePath = $env:PSModulePath + "$([System.IO.Path]::PathSeparator)" + "D:\Ivan\Documents\WindowsPowerShell\Modules"
Now all I had to do is restart the shell, and voila:
PS C:\Users\ivant> $env:PSModulePath
D:\Ivan\Documents\PowerShell\Modules;C:\Program Files\PowerShell\Modules;c:\program files\powershell\7\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules;D:\Ivan\Documents\WindowsPowerShell\Modules