Reputation: 187
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()
}
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.
Is there a way to ensure the Get-SqlVersions
data shows up when calling Test-Function
?
Upvotes: 2
Views: 4271
Reputation: 21
I know this is old, but I stumbled on it and can't help but contribute.
The problem is here:
Get-SqlVersions | Out-String
Change it to this:
Get-SqlVersions | Out-Host
I did some quick looking around, and Out-String seems to collect and prepare things for displaying. Out-Host just does it.
Upvotes: 2
Reputation: 36332
Make it explicitly output to the host.
$GetSQL = Get-SqlVersions | Out-String
Write-Host $GetSQL
Upvotes: 3
Reputation: 9183
Could you please store Get-SqlVersions | Out-String;
in a Variable and display that. I think that should work.
$versions = Get-SqlVersions | Out-String;
$versions
Upvotes: 0