假设我有一个带有描述多个实体的数据的 Obj。我想像这样输出它(CSV、HTML、Format-Table 等):
Property Code Property descr. Entity1 Entity2 Entity3
abs_de234 abs prop for de 132 412 412
abs_fe234 abs prop for fe 423 432 234
... ... ... ... ...
我会使用类似的东西:
$ObjData | % {Select-Object @{Label = "Property Code"; Expression = {$_.propcode}}, @{Label = "Property Desc."; Expression = {$_.descr}}, @{Label = "Entity1"; Expression = {$_.entity1}}, @{Label = "Entity2"; Expression = {$_.entity2}},@{Label = "Entity3"; Expression = {$_.entity3}} }| Format-Table
但是如果我的对象有可变数量的实体怎么办?假设这些属性都在一个数组中:
$EntityList = @('Entity1', 'Entity2', 'Entity4', 'Entity5', 'Entity5')
如何,基于$EntityList
我可以构造相应的Select-Object
命令?
更新。:基于帮助Select-Object
:
Select-Object
[-InputObject <PSObject>]
[[-Property] <Object[]>]
[-ExcludeProperty <String[]>]
[-ExpandProperty <String>]
[-Unique]
[-Last <Int32>]
[-First <Int32>]
[-Skip <Int32>]
[-Wait]
[<CommonParameters>]
这是否意味着我应该能够使用Select-Object -Property $EntityList
?