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.
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.