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"