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
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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.