question

DavidMGrayAdmin-7776 avatar image
0 Votes"
DavidMGrayAdmin-7776 asked IanXue-MSFT commented

$Env:PSModulePath issue

Hello
Quite new to PowerShell on Windows 10 and I'm finding an issue with PSModulePath being set to a network share which I do not want as it takes
an age to load. Strangely the speed issue only manifests itself when I run PS commands in Visual Studio code (preferred option) but not in ISE.

I have tried the following to re-order the search list but it only persists for that session.

$Env:PSModulePath = "C:\Program Files\WindowsPowerShell\Modules;\\domain.com\fileshare\redirected$\first.last\Documents\WindowsPowerShell\Modules;C:\Program Files (x86)\Red Gate\SQL Change Automation PowerShell\Modules\;C:\Program Files (x86)\Microsoft Azure Information Protection\Powershell"

But it is not persisted.

My $PROFILE looks like this.

86190-psprofile.png



I know I need to read up on PS profiles but wanted to get this path stuff sorted first.

Thanks in advanced.

windows-server-powershell
psprofile.png (43.8 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered IanXue-MSFT commented

Hi,

The value of $env:PSModulePath is constructed each time PowerShell starts. What does your $PSVersionTable look like?
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_psmodulepath

Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi
Thanks for your response. Here is my $PSVersionTable

86313-pserror.png


0 Votes 0 ·
pserror.png (20.4 KiB)
IanXue-MSFT avatar image IanXue-MSFT DavidMGrayAdmin-7776 ·

You can add the $Env:PSModulePath line to your profile or edit $Env:PSModulePath using the .Net method SetEnvironmentVariable.

 [Environment]::SetEnvironmentVariable('PSModulePath','C:\Program Files\WindowsPowerShell\Modules;\\domain.com\fileshare\redirected$\first.last\Documents\WindowsPowerShell\Modules;C:\Program Files (x86)\Red Gate\SQL Change Automation PowerShell\Modules\;C:\Program Files (x86)\Microsoft Azure Information Protection\Powershell', 'Machine')

https://docs.microsoft.com/en-us/powershell/scripting/developer/module/modifying-the-psmodulepath-installation-path

0 Votes 0 ·