PSModulePath

Welcome Forums General PowerShell Q&A PSModulePath

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
3 years, 6 months ago.

  • Author
    Posts
  • #25962

    Participant
    Points: 21
    Rank: Member

    I'm not sure if I'm asking the right question or in the right place but here goes. I have added a new path to the PSModulePath at the machine level. I want the modules under this location to be available at any prompt for any user. However the modules at C:\FooBar are only available when the powershell session is run as admin. I have clearly missed something but I'm not sure what. I don't know if it makes any difference but this is 2008 R2 machine running powershell v4.


    # Figure out what is in the powershell module path
    $CurrentValue = [Environment]::GetEnvironmentVariable("PSModulePath", "Machine")
    $CurrentValue.split(';') | sort


    # Add the new path to our module path
    $NewPath = "C:\FooBar"
    [Environment]::SetEnvironmentVariable("PSModulePath", $CurrentValue + ";$NewPath", "Machine")


    # test to ensure that it has just worked – we should see our new path included
    [Environment]::GetEnvironmentVariable("PSModulePath", "Machine")

    I had assumed that this would be the correct way to acomplish what I wanted rather than editing the alluserallhost profile in sys32.

  • #25970

    Member
    Points: 0
    Rank: Member

    You seem to have done everything correctly. Do you have an NTFS permissions problem on C:\FooBar that is preventing non-administrators from reading the scripts, perhaps?

  • #25977

    Participant
    Points: 21
    Rank: Member

    In order for all users to have access to these modules I have had to reboot the machine. Thanks for the response though it certainly made me think.

  • #26176

    Participant
    Points: 0
    Rank: Member

    you need to refresh the environment variable after updating it.

    $env:PSModulePath =[System.Environment]::GetEnvironmentVariable("PSModulePath","Machine") 
    

    That will update the current powershell session and any new sessions opened after the refresh. Any other sessions open at the time of the refresh will see not see the change until they are closed and reopened or you update the variable in that session.

The topic ‘PSModulePath’ is closed to new replies.