最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to change the $PROFILE variable for a duplicated PowerShell instance (copied executable)? - Stack Overflow

programmeradmin3浏览0评论

I copied a powershell.exe file for creating a custom terminal profile but the $PROFILE environment variable remains unchanged. I like it to change when I run the copied executable. I have already tried setting $PROFILE = "C:\New\Path\to\Profile" but this does nothing.

I copied a powershell.exe file for creating a custom terminal profile but the $PROFILE environment variable remains unchanged. I like it to change when I run the copied executable. I have already tried setting $PROFILE = "C:\New\Path\to\Profile" but this does nothing.

Share Improve this question edited 2 days ago M. Damian Mulligan 8738 silver badges19 bronze badges asked Feb 15 at 21:12 RM99RM99 111 silver badge3 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

The value(s) of the automatic $PROFILE variable can not be changed (meaningfully).[1]

Instead of creating a copy of powershell.exe (the Windows PowerShell CLI) in a different location, use the original along with CLI parameters that emulate loading a profile file from a custom location:

powershell.exe -NoProfile -NoExit -File C:\New\Path\to\Profile.ps1

Note: By using -NoProfile, none of the - potentially multiple - profile files will be loaded.


[1] Except indirectly, if you change the location of the well-known Documents folders, which has far-reaching consequences, however. See this answer for details.
The fact that PowerShell even technically allows you to assign a new value to the $PROFILE variable - which, however, has no effect (leaving aside that, conceptually, making this assignment in-session, after the session has already started, would be too late) - should be considered a bug; see this answer.

发布评论

评论列表(0)

  1. 暂无评论