Is it possible to change the default value of $profile to a new value?

So I would rather not create my profile file here:


I mean don't get me wrong, this isn't the end of the world and I can live with it. However, I like to keep root "My Documents" reasonably lean and I really would rather not create a directory there every time I start using a new application.

I've nosed around looking to where this setting might be hidden, but so far no luck. It doesn't seem to be in the registry or any of the $PsHome files.

Do I just have to learn to live with this? . . . or is there a way to change the value of $profile that will "stick" on this system for all time? That is, to change the "default value" of $profile?

The best I've thought of so far, is to ignore $profile and instead put some code in $profile.AllUsersAllHosts to source/execute my file from where I want to put it instead of from the default $profile location.

Comments and/or other suggestions welcomed.



I think your solution to source your "new" profile in the existing profile is probably as good as you're going to get.

The only thing I can think of is "dot sourcing" your profile at the powershell invocation.

For example:

powershell -noprofile -noexit -command "invoke-expression '. ''C:\My profile location\profile.ps1''' "

By changing the script that invoke-expression command points to you can place your "profile" anywhere you'd like. Then, create shortcut that launches PowerShell and set the target to the above command.

Try junctions by running this command in powershell:

cmd /c mklink /J c:\Users\Name\Documents\WindowsPowerShell\ d:\Powershell\Engine\Profile\

For more information about junctions see here.

You can also put your profile file here


If you want to have a separated location for all your profiles and scripts, you can modify your profile.ps1 file above as

 $profile = "NewLocation\profile.ps1"
. $profile

Make sure what type of profile you use, see details here

You can change your $Profile.CurrentUser* paths by changing your personal folder path Environment.GetFolderPath(Environment.SpecialFolder.Personal)

Either via regedit

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

Under the Name column select Personal and chage the value to where you want your profile.

Or via PowerShell

New-ItemProperty 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders' Personal -Value 'Your New Path Here' -Type ExpandString -Force

You have to reboot for this to take effect.

According to Scripting Guy article Understanding the Six PowerShell Profiles, $profile is expanded from $PsHome\Microsoft.PowerShell_profile.ps1; $pshome is the powershell installation directory and a read-only variable; according to a post on this thread, Microsoft tells us this cannot be changed.

This might be more of a workaround, but what I did was create a symbolic link copy of the WindowsPowerShell directory in the location PowerShell was looking at. This is more of a bandaid technique though.

This solution is inspired by RootLoop's answer:

Access your profile by navigating to its location defined by $PROFILE. Then, copy it to the location where you want to store it (C:/NewLocation/profile.ps1). Replace the original profile's contents with the text:

$profile = "C:\NewLocation\profile.ps1"
. $profile

Remember that the profile is just a script that is run as soon as you open powershell. This script above will first set $profile to the new location, so any references to the $profile variable will still work as if you moved it. The next line of code will invoke the new profile with syntax that is called dot sourcing. Effectively, the . $profile line is just running your new profile code.

Next, you can reduce the clutter in your My Documents directory by hiding the Powershell folder. Simply right click on the folder, select "properties", and under the general tab, select "hidden".

Need Your Help

Newtonsoft Serializing object to a custom output

c# c#-4.0 elasticsearch nest-api

I know this is silly question, can anyone help me out on this ...?

Using a quick sort at certain index in 2D list

python list sorting quicksort

I am trying to use a quick sort to sort through a list of lists at index [1]. This is for a school project so I have t use the quick sort algorithm.