powershell - VS Code PowerShell 远程会话寻找本地配置文件
问题描述
我正在使用 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 会话已成功建立,但是,只要我输入第一个命令,远程会话就会循环以下错误,直到我按 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 代码设置。
但这根本没有任何影响。
我还可以看到,在我使用“powershell.enableProfileLoading”建立远程连接后:false,当我在 VS Code 的 Settings-GUI 中勾选(启用)该设置的复选框时,远程会话中的错误消息立即又开始了。
任何想法为什么会发生这种情况表示赞赏。
最好的问候,菲利克斯
解决方案
将PowerShell 集成控制台与*-PSSession
or结合使用时,我遇到了类似的问题Invoke-Command
。
有一个设置可以禁用,默认powershell.integratedConsole.showOnStartup
设置为true
。
当它是 时true
,启动时的默认 shell 是PowerShell Integrated Console,它$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
用作它的配置文件。
干杯!
推荐阅读
- javascript - React / JS Uncaught ReferenceError:未定义要求
- java - Spring Boot QueryDsl java.lang.UnsupportedOperationException
- ros - 从城市场景的点云创建网格
- c - 面临初始化树的问题,即树的根
- react-native - 找不到“NativeReanimated”。验证此名称的模块是否已在本机二进制文件中注册
- php - WooCommerce - 更改运输类别中的产品数量
- ruby - 为什么 pod install 在 macOS 终端中使用另一个版本的 ruby
- sass - 如何自定义 Bootstrap 5 Mixin
- java - 如何验证返回的状态代码是否成功,即使用 Rest Assured 的任何 2xx HTTP 状态代码?
- infinispan - HotRod 客户端不断向关闭服务器发送请求