I've used the following to permanently change the PSModulePath:
[Environment]::SetEnvironmentVariable('PSModulePath', "ABC", "Machine")
This works fine when I call the below (it returns "ABC"):
[Environment]::GetEnvironmentVariable('PSModulePath', "Machine")
But in any Powershell Session when I run:
$env:PSModulePath
I get:
C:\Users\myname\Documents\WindowsPowerShell\Modules;ABC
Where is this path coming from, is it PS5 magic? I've checked the "User" target and this is blank. It's as if something is pre-pending the PSModulePath with this default path?