Last active
November 4, 2018 14:38
-
-
Save mwallner/5736ad119398decbe538bbbcbd1b8978 to your computer and use it in GitHub Desktop.
check how PSModulePath can be modified | ref https://github.com/chocolatey/choco/issues/1668
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ErrorActionPreference = "Stop" | |
function Out-EnvValues($valName, $txt) { | |
$envVarMachine = [Environment]::GetEnvironmentVariable($valName, 'Machine') | |
$envVarUser = [Environment]::GetEnvironmentVariable($valName, 'User') | |
$envVar = Get-Content env:$valName | |
Write-Output "-------------------------------------------" | |
Write-Output "Out-EnvValues: variable '$valName' $txt" | |
Write-Output "machine: '$envVarMachine'" | |
Write-Output "user : '$envVarUser'" | |
Write-Output "env : '$envVar'" | |
Write-Output "-------------------------------------------" | |
} | |
Out-EnvValues "Path" | |
Out-EnvValues "PSModulePath" | |
Write-Output "... subprocess vals ..." | |
powershell.exe -command "write-host env:PSModulePath in subprocess: `$env:PSModulePath" | |
cmd.exe /c "powershell.exe -command ""write-host env:PSModulePath via cmd-subprocess: `$env:PSModulePath""" | |
Write-Output "`r`naction happening...`r`n" | |
$userPSPathOld = [Environment]::GetEnvironmentVariable('PSModulePath', 'User') | |
$userPSPathNew = if ($userPSPathOld -eq "") { "c:/secretModulesPath" } else { "$userPSPathOld;C:/secretModulesPath" } | |
[Environment]::SetEnvironmentVariable('PSModulePath', "$userPSPathNew", 'User') | |
Write-Output "set user/PSModulePath to '$userPSPathNew'" | |
Out-EnvValues "PSModulePath" | |
Write-Output "... subprocess vals ..." | |
powershell.exe -command "write-host env:PSModulePath in subprocess: `$env:PSModulePath" | |
cmd.exe /c "powershell.exe -command ""write-host env:PSModulePath via cmd-subprocess: `$env:PSModulePath""" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adding
Update-SessionEnvironment
did not change anything,$env:PSModulePath
still points to the old USER environment