PowerShell Core 可以使用 Windows 终端而不是 pwsh.exe 控制台吗?

how*_*ode 5 powershell-core windows-terminal

默认的 PowerShell Core (pwsh.exe) 控制台看起来就像命令提示符 (cmd.exe) 控制台。此外,PowerShell Core 控制台也有无法正确显示外文字符(例如韩语、日语等)的限制,除非我更改字体,但我不想这样做。另一方面,Windows 终端可以正确显示外来字符,因为它默认使用 UTF-8。

我使用 AutoHotKey 启动 PowerShell 脚本 (.ps1),我想知道是否可以在 Windows 终端中打开该脚本并自动使用 PowerShell Core?我需要执行任何配置更改吗?

小智 6

是的,您可以执行类似的操作,启动 Windows 终端并将 PowerShell 核心添加为配置中的默认值,可以使用密钥进行访问,您只需更改Power shell 核心crtl+,的 id 即可。defaultProfile

下面的例子:

{
"$schema": "https://aka.ms/terminal-profiles-schema",

"defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",

"profiles":
{
    "defaults":
    {
        // Put settings here that you want to apply to all profiles
    },
    "list":
    [
        {
            // Make changes here to the powershell.exe profile
            "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
            "name": "Windows PowerShell",
            "commandline": "powershell.exe",
            "hidden": false
        },
        {
            // Make changes here to the cmd.exe profile
            "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
            "name": "cmd",
            "commandline": "cmd.exe",
            "hidden": false
        },
        {
            "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
            "hidden": false,
            "name": "Azure Cloud Shell",
            "source": "Windows.Terminal.Azure"
        },
        {
            "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
            "hidden": false,
            "name": "PowerShell",
            "source": "Windows.Terminal.PowershellCore"
        }
    ]
},
Run Code Online (Sandbox Code Playgroud)