Microsoft Teams and Skype for Business News and Thoughts

Tom Arbuthnot MVP
Tom Arbuthnot MCSM Communications

This site uses cookies

Find this blog useful? Please take a second to share, thanks!

PowerShell Add a Persistent Module Path to $env:PSModulePath

Published 30/06/2013 - 3 Comments

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

image

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:

image

after update we see the registry is updated:

image

New PowerShell Session:

image

Credit for Technique:

http://blogs.technet.com/b/heyscriptingguy/archive/2011/07/23/use-powershell-to-modify-your-environmental-path.aspx

Tom Arbuthnot

Tom Arbuthnot

Principal Solutions Architect at Modality Systems
Tom Arbuthnot is Principal Solutions Architect at Unified Communications specialist Modality Systems. He is a Microsoft Certified Master and MVP, blogger, has a regular podcast with UCToday at tomtalks.show and is a regular speaker at events including Microsoft TechEd and Ignite. He co-runs The Microsoft UC User Group London.

3 comments

Gaston - 14/03/2014 Reply

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 ;)

Daniel - 27/03/2018 Reply

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.

Leave a Reply:


close

Weekly Email Update 
of all the key 
Microsoft Teams and Skype for Business News
every Tuesday

No Spam ever, I promise - Tom