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

Is something wrong with my $PROFILE environment variable?

如果我执行

& $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 找到了正确的配置文件。我的设置有问题吗?

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

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

& $Profile.CurrentUserAllHosts

作为脚注,$Profile 只是扩展的 System.String,添加了属性和修改的 ToString 方法。参见:

$Profile | Get-Member -MemberType NoteProperty

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

我 运行 在设置 oh-my-posh 时遇到了这个问题,因为我的工作计算机的配置方式。

我刚刚创建了丢失的文件,然后一切正常。