如何在不充斥PowerShell控制台的情况下显示命令的输出?

时间:2012-06-29 15:11:45

标签: powershell

我正在从.ps1安装脚本运行静默SQL安装程序。 SQL安装程序设置为/ Quiet和/ DisplayProgress。我最近把它发送到一个新的控制台窗口来显示输出但没有淹没控制台,但是最近我通过Enter-PSSession进行了远程控制的切换,所以我不会看到新的窗口。

有没有办法可以使用Write-Progress或其他东西一次显示6条滚动线?

1 个答案:

答案 0 :(得分:0)

您可以尝试这样的事情:

function Write-SomeContent {
    [CmdletBinding()]
    param (
        [Object[]] $Content
    )

    Clear-Host;
    $pos = New-Object -TypeName System.Management.Automation.Host.Coordinates;
    $pos.X = 0;
    $pos.Y = 0;
    $Host.ui.RawUI.CursorPosition = $pos;

    foreach ($Object in $Content) {
        Write-Host -Object $Object;
    }
}

Write-SomeContent 'Message 1', 'Message 2', 'Message 3', 'Message 4', 'Message 5', 'Message 6';

只需继续调用Write-SomeContent,它只会占用与传入它的对象一样多的行。