Powershell: $profile and $profilehome have strage behavior

Created on 26 Mar 2020  路  4Comments  路  Source: PowerShell/PowerShell

Steps to reproduce

> $profile
> $profilehome

Expected behavior

> $profile
C:\Users\<user>\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

> $profilehome
C:\Users\<user>\Documents\WindowsPowerShell

Actual behavior

> $profile
C:\Users\<user>\Documents\*PowerShell*\Microsoft.PowerShell_profile.ps1

> $profilehome
<blank>

Environment data


Name                           Value
----                           -----
PSVersion                      7.0.0
PSEdition                      Core
GitCommitId                    7.0.0
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0鈥
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

The expected behavior is what is current behavior in PS5. As I have lots of scripts in my profile that uses $profilehome it is strange behavior that renaming the profile folder. If the $profilehome were populated, I could have taken that into account in my init scripts, but it is not.

Issue-Question Resolution-Answered

Most helpful comment

Good point, @doctordns, but please note that 'Mark' and 'Michael' can be side-by-side installations too; personally, I only have the latter installed. 馃槣

All 4 comments

$profilehome is not an automatic (built-in) variable.

What $PROFILE points to was changed by design in PS Core, since you may want to have a profile that takes advantage of features only available in PS Core (and vice versa).

You can place the following in your PS Core $PROFILE to dot-source the WinPS one:

if ($IsWindows) {
 . ($PROFILE -replace '\\PowerShell\\', '\WindowsPowerShell\')
}

As Mark says, this is by design and enables you to have side by side installations - using windows PowerShell and open-source PowerShell where each makes sense.

Good point, @doctordns, but please note that 'Mark' and 'Michael' can be side-by-side installations too; personally, I only have the latter installed. 馃槣

Typos 'r Us...

Was this page helpful?
0 / 5 - 0 ratings