What bugs me is that this command works fine when i run it from the command line, i.e. the “documents\WindowsPowerShell\Modules” location is added to the $env:PSModulePath.
but when I add the very same line to my $PROFILE it does not work. I get the error:
Join-Path : Cannot bind argument to parameter ‘Path’ because it is null.
At C:\Users\Joakim\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:3 char:44
Ok, I could do that… but my intention with setting up the modulepath in the profile is to not make anything machine specific. I did find something interesting.
If I replace ${env:HOME} with ${env:USERPROFILE} everything works. So now I am really curious, why is the environment variable USERPROFILE available but not the HOME variable? Weird.
I have no HOME environment variable on my system. There’s an automatic $home variable in PowerShell, and as you already pointed out, there’s also a USERPROFILE environment variable.
Thanks Dave, as I updated my post to say, I ended up using the $env:USERPROFILE variable which is a System.Environment variable and therefore is available also when the PowerShell profile is executing.
All I was pointing out is that there’s a difference between $env:home and $home. On my computer, $env:home never exists, but $home works just like $env:USERPROFILE (regardless of when you use it; works fine in a profile as well.)
Edit: On a side note, the $home variable is initialized from the values of $env:HOMEDRIVE and $env:HOMEPATH , which may or may not be the same as $env:USERPROFILE (depending on how the Profile tab of your account is set up.)