Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
725 views
in Technique[技术] by (71.8m points)

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

So I would rather not create my profile file here:

C:UsersfmerrowDocumentsWindowsPowerShellMicrosoft.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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 locationprofile.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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...