如何在VS Code中启动Windows PowerShell (v5)终端会话?
解决VS Code默认启动PowerShell 7而非PowerShell 5的问题
确认终端配置文件的路径正确性
打开VS Code设置(快捷键Ctrl+,),搜索terminal.integrated.profiles.windows,找到Windows PowerShell的配置项,确保path字段指向C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe——这是PowerShell 5的默认路径。如果这里的路径写成了pwsh.exe,直接修正即可。正确配置示例:
"Windows PowerShell": { "source": "PowerShell", "path": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "icon": "terminal-powershell" }
核对默认终端设置项
接着搜索terminal.integrated.defaultProfile.windows,确认它的值是"Windows PowerShell",而非"PowerShell"——后者通常对应PowerShell 7的配置。
手动写入完整配置(若前两步无效)
如果上述配置看起来正常但问题依旧,直接打开settings.json(点击设置界面右上角的{}图标进入),手动添加或覆盖以下配置:
"terminal.integrated.profiles.windows": { "PowerShell 7": { "source": "PowerShell", "path": "pwsh.exe", "icon": "terminal-powershell" }, "Windows PowerShell": { "path": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "icon": "terminal-powershell" } }, "terminal.integrated.defaultProfile.windows": "Windows PowerShell"
这种方式明确区分两个版本的路径,避免VS Code混淆配置。
重启VS Code生效
修改配置后,彻底关闭VS Code(包括后台进程)再重新打开,测试新终端是否启动PowerShell 5。
临时启动PowerShell 5的快速方法
若不想修改配置,可直接点击终端面板右上角的下拉箭头,从列表中选择Windows PowerShell启动会话。
内容的提问来源于stack exchange,提问作者Marc
相关产品推荐
相关产品推荐

