You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Windows 10中通过编程修改PowerShell控制台字体与布局

如何在Windows 10中通过编程修改PowerShell控制台设置?

在全新安装Windows后,需要将原生PowerShell控制台调整为以下参数:

  • 字体大小18
  • 屏幕缓冲区大小9999
  • 窗口宽度140
  • 窗口高度32

目前尚未找到可行方法,以下是尝试过但无效的方案:

方案1:直接修改控制台属性的PowerShell脚本

最初尝试通过脚本直接修改控制台属性,但无法生效:

$fontSize = 18
$screenBufferSize = 9999
$windowSize = 140
$windowHeight = 32

function Set-ConsoleSettings {
    param (
        [int]$FontSize,
        [int]$ScreenBufferSize,
        [int]$WindowSize,
        [int]$WindowHeight
    )

    $font = New-Object System.Drawing.Font("Consolas", $FontSize)
    $host.UI.RawUI.GetType().GetProperty("FontSize").SetValue($host.UI.RawUI, $font.Size, $null)
    $host.UI.RawUI.BufferSize = New-Object Management.Automation.Host.Size($ScreenBufferSize, $WindowSize)
    $host.UI.RawUI.WindowSize = New-Object Management.Automation.Host.Size($WindowSize, $WindowHeight)
}

# 修改普通权限PowerShell控制台
Set-ConsoleSettings -FontSize $fontSize -ScreenBufferSize $screenBufferSize -WindowSize $windowSize -WindowHeight $windowHeight

# 修改管理员权限PowerShell控制台
Start-Process powershell.exe -ArgumentList "-NoProfile -Command Set-ConsoleSettings -FontSize $fontSize -ScreenBufferSize $screenBufferSize -WindowSize $windowSize -WindowHeight $windowHeight" -Verb RunAs

方案2:创建带自定义设置的快捷方式

尝试创建包含自定义设置的快捷方式,计划固定到任务栏,但同样失败:

# 定义目标设置
$fontSize = 18
$screenBufferSize = 9999
$windowSize = 140
$windowHeight = 32

# 创建带自定义字体大小的PowerShell快捷方式
$shortcutPath = "$env:USERPROFILE\Desktop\CustomPowerShell.lnk"
$shell = New-Object -ComObject WScript.Shell
$shortcut = $shell.CreateShortcut($shortcutPath)
$shortcut.TargetPath = "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe"
$shortcut.Arguments = "-NoProfile -ExecutionPolicy Bypass -Command `$host.UI.RawUI.FontSize=$fontSize; `$host.UI.RawUI.BufferSize=New-Object Management.Automation.Host.Size($screenBufferSize, $windowSize); `$host.UI.RawUI.WindowSize=New-Object Management.Automation.Host.Size($windowSize, $windowHeight)"
$shortcut.Save()

Write-Host "自定义PowerShell快捷方式已创建在桌面。"

额外要求

不接受“安装Windows Terminal”的解决方案,需针对原生Windows进行配置,最终希望通过autounattend.xml分发标准化设置。

内容的提问来源于stack exchange,提问作者YorSubs

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 22:45:15