如果我执行
& $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
此外,除非将-NoProfile
传递给可执行文件,否则在启动该shell时会自动执行应用于当前shell的配置文件。