在读取主机之前显示输出 [英] Show output before Read-Host

查看:29
本文介绍了在读取主机之前显示输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在获取一些信息以在读取主机之前写入控制台时遇到了一些问题.让我抛出一个简化的例子.

I'm having some issues getting some info to write to the console before Read-Host. Let me throw out a simplified example.

Function Add-Build {
[CmdletBinding()]
Param ([Parameter(Mandatory=$True,Position=1)][String]$Build
      ,[Parameter(Mandatory=$False,Position=2)][System.Nullable``1[[System.Int32]]]$VersionID
      ,[Parameter(Mandatory=$False,Position=3)][String]$BuildDescription
)

    Write-Host -BackgroundColor DarkYellow "Adding SQL Build $($Build)"


IF ($VersionID -eq $null)
{
    Get-SqlVersions | Out-String


    $VersionID = Read-Host -Prompt "SELECT Version (Enter To Skip)" | % { IF ($_ -eq '') {$null} ELSE {$_}}
    }
}

FUNCTION Test-Function {

   $BuildID = (Get-BuildID -Build "11.0.3156.0").ToString()
}

如果我直接调用 Add-Build 那么 Get-SqlVersions |Read-Host. 之前的 Out-String 输出.如果我调用 Test-Function 虽然 Get-SqlVersions 不再输出到控制台.Get-SqlVersions 进行 SQL proc 调用,输出是几个 Datarows.

If I call Add-Build directly then the Get-SqlVersions | Out-String output before the Read-Host. If I call Test-Function though the Get-SqlVersions no longer outputs to the console at all. Get-SqlVersions makes a SQL proc call and the output is a couple Datarows.

有没有办法确保在调用 Test-Function 时显示 Get-SqlVersions 数据?

Is there a way to ensure the Get-SqlVersions data shows up when calling Test-Function?

推荐答案

使其明确输出到主机.

$GetSQL = Get-SqlVersions | Out-String
Write-Host $GetSQL

这篇关于在读取主机之前显示输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆