'Powershell $PROFILE variable pointing to wrong location. Where is $PROFILE variable it set?

After doing some changes to my machine, Powershell fails because the $PROFILE variable points to a different location than before, i.e. it is set to

C:\Powershell\Microsoft.PowerShell_profile.ps1

instead of

C:\Users\user\Documents\Powershell\Microsoft.PowerShell_profile.ps1

This causes problems like installed modules not found and more. So my question is how does Powershell set the value of $PROFILE? Can it be changed?



Solution 1:[1]

I came across this while searching for an answer.

To change where Powershell will look for the default profile you need to change a registry key.

Please note that the profile wil be found under a new directory WindowsPowerShell/Microsoft.PowerShell_profile.ps1.

Desired path: C:/Users/admin Powershell profile: C:/Users/admin/WindowsPowerShell/Microsoft.PowerShell_profile.ps1


Manual way:

Open up the Registry Editor and navigate to:

Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders

Change the value of Personal to the directory of your choice.


Automated way with powershell:

Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "Personal" -Value "DRIVEHERE"

Then you can test the value was set with:

Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "Personal"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1