小编Whi*_*ane的帖子

PowerShell 配置文件未加载

我创建了文件C:\Users\<myname>\Documents\WindowsPowerShell\profile.ps1;但是,PowerShell 不会在启动时加载它。我已经测试了默认的 PowerShell 以及 VS Code 的集成 PowerShell。我也尝试将profile.ps1文件重命名为Microsoft.PowerShell_profile.ps1,但这没有任何改变。每次更改后,我都会重新启动有问题的应用程序。

运行Test-Path $profile.CurrentUserAllHosts返回 True。

配置文件当前仅包含一行 ( Set-PSReadlineKeyHandler -Key Tab -Function Complete)。启动 PowerShell 或 VS Code 的集成 shell 后,运行Get-PSReadlineKeyHandler | findstr -i Tab显示尚未设置。复制并粘贴配置文件中的行,运行它,然后Get-...再次运行该命令显示它已正确设置,并且更改做了它应该做的。重新启动外壳将恢复为默认设置。

我是否还需要执行其他步骤才能让 PowerShell 执行配置文件?(我来自 Linux/UNIX 背景,我认为 PowerShell 的工作方式类似,但当然 PowerShell 的设计完全不同)。如果没有额外的步骤,为什么 PowerShell 在这种情况下不加载配置文件?

附加信息:

> $profile | Format-List * -force
AllUsersAllHosts       : C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
AllUsersCurrentHost    : C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
CurrentUserAllHosts    : C:\Users\<myname>\Documents\WindowsPowerShell\profile.ps1
CurrentUserCurrentHost : C:\Users\<myname>\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
Length                 : 76
Run Code Online (Sandbox Code Playgroud)

powershell

10
推荐指数
1
解决办法
2万
查看次数

标签 统计

powershell ×1