Reputation: 23
Using Out-GridView, how do you control what the column names are? I would like something meaningful for the column names instead of “string” - is this possible?
[string] $colLabel = 'MyLabel'
[string] $a = 'a'
[string] $b = 'b'
$Selected = ($colLabel), ($a), ($b) | Out-GridView
Upvotes: 1
Views: 2036
Reputation: 27408
The typical pattern would be:
[pscustomobject]@{
colLabel='MyLabel'
a='a2'
b='b2'
} | Out-GridView
or
get-process | select-object name,id,ws | Out-GridView
Here's 1 example of a calculated property:
1 | select-object @{ n='Num'; e={$_} }
Num
---
1
Upvotes: 3
Reputation: 15470
Sure, use a temporary CSV file:
[string] $colLabel = 'MyLabel'
[string] $a = 'a'
[string] $b = 'b'
@"
$($colLabel)`,
$($a)`,
$($b)
"@ | Set-Content temp.csv
Import-Csv temp.csv | Out-GridView
Remove-Item temp.csv
First it creates a temporary csv file, then imports and passes to grid view and then deletes it.
Upvotes: 0