3

I just installed windows 11 on my new PC, prior to this I was using Windows 10. I was setting up my terminal when I realized that the $profile environment variable points to a onedrive document folder rather than a local folder like how it does by default on Windows 10

PS C:\Users\eclipse> echo $PROFILE
C:\Users\eclipse\OneDrive\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

While I could technically just create the file in the onedrive folder I really do not want to store any of my files on the cloud and Id much rather prefer to have it at C:\Users\eclipse\Documents\PowerShell\Microsoft.PowerShell_profile.ps1. This is the default value stipulated by microsoft as well for current user current profile. How can I permanently change $profile to achieve this?

eclipse
  • 197
  • 1
  • 5
  • 16

2 Answers2

1

As far as I know, you can't change the default environment variable $profile. Your default probably comes from having your default document folder in the OneDrive. Either disable this option in the OneDrive settings on your computer or link your new folder in the current profile ps1.

C:\Users\eclipse\OneDrive\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

$profile = C:\Users\eclipse\Documents\PowerShell\
.$profile
Lukas
  • 138
  • 6
0

PowerShell refers to the Personal value of your user folders. If you're a OneDrive user and have enabled OneDrive to backup your Documents Files, it is set to C:\Users\<USERNAME>\OneDrive\Documents.

You can change/check the option by going to OneDrive Settings > Sync and backup > Manage backup

Sharing the same profile across various devices can lead to issues, e.g. when you have a certain packages installed on one machine, but not on the other. To work around this problem, there are two main options:

1. To have the shared profile refer to a local copy on your machine (preferred)

2. To edit the registry so that your documents folder points to a local directory (not preferred)

Create Local Folder and Copy Profile

To find the location of your current profile open PowerShell and run echo $profile

Create a new local directory, e.g. C:\Users\<USERNAME>\Documents\PowerShell\

Copy the PowerShell profile from the C:\Users\<USERNAME>\OneDrive\Documents\PowerShell\ directory to your new, local directory . Do not move the file! Make a copy!

Option A: Add a Link to a Local Profile

Go to the C:\Users\<USERNAME>\OneDrive\Documents\PowerShell\ directory and open the Microsoft.PowerShell_profile.ps1 file in a editor. Make sure you're editing the shared profile and not your local copy!

Clear the file and add the following line to let the shared profile refer to the copy in your local directory/copy,

&"$($UserProfile)Documents\PowerShell\Microsoft.PowerShell_profile.ps1"

Option B: Edit Registry to Change Location of User Shell Folder

Editing the registry to change the location of the User Shell folder can have knock-on effects. So it's better not to do it this way!

To change the registry, run

Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "Personal" -Value "C:/Users/<USERNAME>/Documents/PowerShell/"

To test the value was set correctly, run

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

Bobbie E. Ray
  • 635
  • 7
  • 8