您可以更改窗口标题,它的功能类似于标题 - 虽然我不知道它是否会提供您正在寻找的内容:
$Host.UI.RawUI.WindowTitle = "Your Custom Header"
jumbo 提出的使用 Write-Progress cmdlet 的建议可能与纯 PowerShell 中的页脚一样好。
另一种选择是在 WinForms/WPF 应用程序中托管 PowerShell 运行时,它会为您提供适当的页眉/页脚 - 尽管这可能完全是矫枉过正,而且根本不符合您的需求。在一个过于简单和做作的例子中,你会在 C# 中做这样的事情:
// include the System.Management.Automation assembly & namespace
PowerShell ps = PowerShell.Create();
ps.AddCommand("Get-Process");
foreach (PSObject result in ps.Invoke()) {
Console.WriteLine(result.Members["ProcessName"].Value);
}
您可能会将输出转储到 TextBox 或更合适的东西,而不是写入控制台。
最后一个选项是使用控制台设置CursorPosition 属性的功能。这又是一种 hack,因为您将覆盖将滚动的输出,但如果您的脚本输出有限 - 这可能有效:
$pos = $Host.UI.RawUI.CursorPosition
$newPos = New-Object System.Management.Automation.Host.Coordinates 0,20
$Host.UI.RawUI.CursorPosition = $newPos
"Here is my footer on starting at the first character of line 20"
$Host.UI.RawUI.CursorPosition = $pos
您可以动态检查$Host.UI.RawUI.WindowSize.Height 属性以将页脚设置在窗口底部附近。请记住,默认情况下,如果有大量输出,文本会滚动 - 其中包括旧版本的页脚也会向上滚动屏幕。