代码之家  ›  专栏  ›  技术社区  ›  stib

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

  •  1
  • stib  · 技术社区  · 7 年前

    如果我执行

    & $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 . 我的设置有问题吗?

    1 回复  |  直到 7 年前
        1
  •  4
  •   Maximilian Burszley    7 年前

    此行为的原因是的默认选择 $Profile.ToString() 当您使用 & $Profile.CurrentUserCurrentHost ).

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

    & $Profile.CurrentUserAllHosts
    

    作为脚注, $Profile 这只是一个延伸 System.String 具有添加的属性和修改的 ToString

    $Profile | Get-Member -MemberType NoteProperty
    

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

    推荐文章