【问题标题】:VS Code PowerShell Remote Session looking for local ProfileVS Code PowerShell 远程会话寻找本地配置文件
【发布时间】:2020-07-01 03:32:14
【问题描述】:

我正在使用 PowerShell 扩展 2020.6.0 的 Windows 10 上运行 VS Code 1.46.1。在其他设置中,我设置了

[...]
"terminal.integrated.shell.windows": C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"powershell.enableProfileLoading": true,
[...]

在 VS 代码中。

现在,每当我使用 PowerShell 集成控制台通过以下命令建立 PS 远程会话时

Enter-PSSession -computername ABC.domain.com -Credential (Get-Credential) -Authentication CredSSP

PS Session 建立成功,但是,只要我输入第一个命令,远程会话就会循环以下错误,直到我按 CTRL + C:

The term 'C:\Users\UserOnClient\Documents\WindowsPowerShell\Microsoft.VSCode_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.
    + CategoryInfo          : ObjectNotFound: (C:\Users\FelTie...ode_profile.ps1:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

从显示的路径中,我知道它必须来自建立远程会话的客户端。这发生在各种远程 PC 上,但在从普通 PS 或 PS ISE 建立 PS 会话时不会发生。

我可以通过设置解决问题

[...]
"powershell.enableProfileLoading": false,
[...]

但是,我依赖于在本地 PC 上加载我的个人资料。

所以我猜测问题一定与集成控制台在启动(远程会话)时加载了一些配置文件有关,所以我添加了

    "terminal.integrated.shellArgs.windows": "-NoProfile",

到 VS Code 设置。

但这根本没有任何影响。

我还可以看到,在我使用“powershell.enableProfileLoading”建立远程连接后:false,当我在 VS Code 的 Settings-GUI 中勾选(启用)该设置的复选框时,错误消息在远程会话立即重新开始。

感谢任何想法为什么会发生这种情况。

最好的问候, 费利克斯

【问题讨论】:

    标签: powershell visual-studio-code powershell-remoting


    【解决方案1】:

    在将 PowerShell 集成控制台*-PSSessionInvoke-Command 结合使用时,我遇到了类似的问题。

    您可以禁用一个名为powershell.integratedConsole.showOnStartup 的设置,默认设置为true

    当它是true 时,启动时的默认shell 是PowerShell 集成控制台,它使用$ENV:UserProfile\Documents\WindowsPowerShell\Microsoft.VSCode_profile.ps1 作为其配置文件。 (这是我失败的地方)

    当这是 false 时,您不再使用 PowerShell 集成控制台,因此 $profile 回退到 $ENV:UserProfile\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1。使用此配置文件,我可以远程执行命令,而不会引发与 [profile] 文件相关的任何异常。

    您也可以使用+ 添加一个新终端,这毫无价值。假设 PowerShell 是您的默认 shell,它应该启动一个使用 Microsoft.PowerShell_profile.ps1 作为其配置文件的新控制台。

    干杯!

    【讨论】:

      猜你喜欢
      • 2011-02-28
      • 1970-01-01
      • 2022-11-24
      • 2011-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多