Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

powershell

So I would rather not create my profile file here:

C:\Users\fmerrow\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 

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.

Frank

like image 479
Frank Merrow Avatar asked Feb 23 '11 18:02

Frank Merrow


2 Answers

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.

like image 143
zdan Avatar answered Sep 21 '22 12:09

zdan


You can also put your profile file here

C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1 

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

https://technet.microsoft.com/en-ca/library/dd819434.aspx

like image 43
Root Loop Avatar answered Sep 17 '22 12:09

Root Loop