powershell - 控制 Powershell 控制台的窗口位置

标签 powershell batch-file

这有效:

(Get-Host).UI.RawUI
$a = (Get-Host).UI.RawUI
$a.BackgroundColor = "white"
$a.ForegroundColor = "black"

$size = (Get-Host).UI.RawUI.WindowSize
$size.Width = 80
$size.Height = 30
(Get-Host).UI.RawUI.WindowSize = $size

但这不起作用,我不知道如何让它发挥作用:

$position = (Get-Host).UI.RawUI.Windowposition
$position.X = 0
$position.Y = 30
(Get-Host).UI.RawUI.Windowposition = $position

我得到的错误很奇怪。当我尝试设置外部窗口位置时,它提示“缓冲区”:

Exception setting "WindowPosition": "Cannot use the 
specified Window X (column) position because it extends 
past the width of the screen buffer. Specify another X 
position, starting with 0 as the left most column of 
the buffer.

最佳答案

这个错误并不奇怪,因为 WindowPosition 获取并设置 View 窗口相对于屏幕缓冲区的位置(以字符为单位)。

它并没有设置Window的位置,而是粗略地说,就是通过窗口的 View 看到的缓冲区中的位置。因此,在您的情况下,您会收到错误,因为它位于缓冲区之外。

http://msdn.microsoft.com/en-us/library/system.management.automation.host.pshostrawuserinterface.windowposition%28v=vs.85%29.aspx

不幸的是,设置窗口的位置并不简单。不过有一个管理单元 - http://wasp.codeplex.com/ (使用Set-WindowPosition)

关于powershell - 控制 Powershell 控制台的窗口位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7603611/

相关文章:

powershell - 如何制作包含今天日期的文件夹,然后将文件复制到其中?

mysql - 批量插入SQL语句

file - 如何使用批处理检测 .txt 文件中的更改?

r - 从批处理文件执行 Rscript - 无法正确处理 "Umlaute"(ä, ö, ü)

powershell - 将 SecureString 变量传递给只读域 Controller 的 DSC 配置

excel - 如何通过Powershell查看Excel安装的是64位还是32位?

windows - 如何从 Powershell 调用 GetStdHandle、GetConsoleMode?

powershell - 从远程命令调用获取输出

powershell - 在生产环境中做 Set-executionpolicy 的常见做法是什么?

string - PowerShell 中的多行字符串到单行字符串的转换