使用 Out-GridView,如何控制列名是什么?我想要一些对列名有意义的东西,而不是“字符串”——这可能吗?
[string] $colLabel = 'MyLabel'
[string] $a = 'a'
[string] $b = 'b'
$Selected = ($colLabel), ($a), ($b) | Out-GridView
使用 Out-GridView,如何控制列名是什么?我想要一些对列名有意义的东西,而不是“字符串”——这可能吗?
[string] $colLabel = 'MyLabel'
[string] $a = 'a'
[string] $b = 'b'
$Selected = ($colLabel), ($a), ($b) | Out-GridView
典型的模式是:
[pscustomobject]@{
colLabel='MyLabel'
a='a2'
b='b2'
} | Out-GridView
或者
get-process | select-object name,id,ws | Out-GridView
这是计算属性的 1 个示例:
1 | select-object @{ n='Num'; e={$_} }
Num
---
1
当然,使用临时 CSV 文件:
[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
首先,它创建一个临时 csv 文件,然后导入并传递给网格视图,然后将其删除。