Reputation:
My best guess is this has something to do with the default output methods used in the Powershell console, but I am at a wall...
I am working on a script that contains a data table of default values found for configuration options in a SQL Server instance. I then have a function that goes and pulls the current in use values of those same configuration options.
I want to output two sets of information from this function: (1) filters specific information out of the current values itself and (2) filters specific information comparing the default values to the current values. So it would look something similar to this (leaving out the data table stuff):
$var1 = $current | where {my filters} |
Select @{label='name';Expression{stuff}},
@{label='value_in_use';Expression{stuff}},
@{label='value';Expression{stuff}}
$var2 = foreach ($o in $tblDefault) {
$current | where {my filters} |
Select @{label='name';Expression{stuff}},
@{label='value_in_use';Expression{stuff}},
@{label='default';Expression{stuff}}
Write-Host "This is a message"
$var1
Write-Host "This is a message"
$var2
}
My issue is with the output of the two variables.
$var2
, "default", is not showing. $var1
.
Get-Member
on the function and it shows the property names only for the first variable.
What am I supposed to do in order to force this into separate objects (meaning column headings for both sets?
Just pasting this together with MSPaint this is the output I expected, and would like:
Upvotes: 1
Views: 1530
Reputation: 16626
Adding out-default when outputting your variables should fix your problem:
Write-Host "This is a message"
$var1
Write-Host "This is a message"
$var2 | out-default
Why? Because you are forcing out-default to look at the first item of $var2, instead of having it look at the first item of the entire stream (returned by your function). This blog post explains how powershell formatting and outputting works.
Upvotes: 2