This topic contains 3 replies, has 3 voices, and was last updated by
June 5, 2015 at 2:25 am #25962ParticipantPoints: 21Rank: 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
I had assumed that this would be the correct way to acomplish what I wanted rather than editing the alluserallhost profile in sys32.
June 5, 2015 at 4:13 am #25970MemberPoints: 0Rank: 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?
June 5, 2015 at 7:55 am #25977ParticipantPoints: 21Rank: 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.
June 8, 2015 at 10:45 pm #26176ParticipantPoints: 0Rank: Member
you need to refresh the environment variable after updating it.
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.