【发布时间】:2016-11-14 20:31:22
【问题描述】:
我是 Powershell 的新手,我正在尝试让重复输出兼容以便能够使用 ConvertTo-Html。我在 PSCustomObject 中有一个字符串以及一些数组。我正在尝试使用以下内容进行去特征化,但是标题属性没有像我期望的那样重复
编辑 - 输出如下
Title Comment
Hello World hello
Hello World bye
已编辑,因为我错过了最后一个选择行(这里我希望标题随着数组的扩展在每一行上重复)
$report = @()
$col1 = @()
$col1 += "hello"
$col1 += "bye"
$col2 = @()
$col2 += "blue"
$col2 += "green"
$col2 += "red"
$reportinfo = New-Object PSCustomObject
$reportinfo | Add-Member NoteProperty -name Title -value [String]"Hello World"
$reportinfo | Add-Member NoteProperty -name Comment -value $col1
$reportinfo | Add-Member NoteProperty -name Colour -value $col2
$report += $reportinfo
$report | select Title -ExpandProperty Comment
这将返回以下输出
你好
再见
如果我使用
Write-Output $report
我得到以下信息
标题注释颜色
----- -------- ------
[String]Hello World {hello, bye} {blue, green, red}
我已经尝试过使用字符串转换和不使用。任何想法将不胜感激。
【问题讨论】:
-
刚试过没有[string]。完美运行。像这样:
$reportinfo | Add-Member NoteProperty -name Title -value "Hello World" -
我的错,错过了最后一行代码 - 请参阅上面的编辑
-
好的,我想我得到了你想要做的,但我不确定它是否可能开箱即用。您将不得不等待比我更聪明的人;)
-
您实际上希望如何格式化输出?你希望每个数组都被展平成一个字符串吗?你能告诉我们想要的结果是什么样的吗?
-
关于预期的(也许是有希望的)期望输出见上文
标签: arrays powershell select pscustomobject