我的$ PROFILE环境变量有问题吗?

问题描述 投票:1回答:1

如果我执行

& $PROFILE

我收到这个错误

& : The term 'C:\Users\stib\Documents\WindowsPowerShell\
Microsoft.PowerShell_profile.ps1' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name,
or if a path was included, verify that the path is correct and try again.
At line:1 char:3
+ & $PROFILE
+   ~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\stib...ell_profile.ps1:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

$PROFILE.CurrentUserAllHosts找到了正确的配置文件。我的设置有问题吗?

powershell windows-10 profile
1个回答
4
投票

这种行为的原因是$Profile.ToString()的默认选择,当您使用&运算符($Profile.CurrentUserCurrentHost)调用它时会调用它。

有选择地执行您的配置文件而不是依赖于默认值:

& $Profile.CurrentUserAllHosts

作为脚注,$Profile只是一个扩展的System.String,具有附加属性和改进的ToString方法。看到:

$Profile | Get-Member -MemberType NoteProperty

此外,除非将-NoProfile传递给可执行文件,否则在启动该shell时会自动执行应用于当前shell的配置文件。

© www.soinside.com 2019 - 2024. All rights reserved.