One of the benefits or using or writing module in PowerShell version 3 or above is that they auto load as you need them. They do this if the modules sit in a number of predefined paths. Often you might want to add an additional persistent path to check for modules to auto load.
This information is actually held in the registry, you can see it by $env:PSModulePath or by looking in the registry
If you want to add a custom path that persists accross PowerShell sessions you can follow these steps running a PowerShell session as administrator:
$originalpaths = (Get-ItemProperty -Path ‘Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment’ -Name PSModulePath).PSModulePath
# Add your new path to below after the ;
$newPath=$originalpaths+’;C:\Users\Tom\SkyDrive\PowerShell\’
Set-ItemProperty -Path ‘Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment’ -Name PSModulePath –Value $newPath
Example:
after update we see the registry is updated:
New PowerShell Session:
Credit for Technique:
Is this the best way to achieve this compared to modifying default PowerShell profile ?
Will this registry modification be erased if the upgrade PowerShell version ?
Thank you Tom for sharing this tip with us ;)
[…] https://tomtalks.mystagingwebsite.com/2013/06/powershell-add-a-persistent-module-path-to-envpsmodulepath/ […]
Hi Tom
Great post as it helped me fix a broken PS / ISE on a dev server.
I ended up editing the PSModule Path variable from Advanced Settings in Control Panel as I wasn’t convinced the changes you describe would persist following a reboot.
I did this way too. Thanks for the tip.
Thank you from Detroit!