【发布时间】:2017-03-19 18:45:04
【问题描述】:
我正在尝试使用来自另一个对象的数据输入来创建一个新的自定义对象。
$clusters = Get-EMRClusters
$runningclusters = $clusters | Where-Object {
$_.Status.State -eq "Running" -or
$_.Status.State -eq "Waiting"
}
$runningclusters 看起来像
id 名称状态 -- ---- ------ j-12345 cluster1 正在运行 j-4567 cluster2 正在运行
我想创建一个新的 PSobject $o,其第 4 列名为 PendingShutdown,它是一个布尔值。
id 名称状态pendingshutdown -- ---- ------ --------------- j-12345 cluster1 运行 False j-4567 cluster2 运行 False
我试过运行这个:
$o = New-Object PSObject
$o | Add-Member -NotePropertyName id -NotePropertyValue $runningclusters.id
$o | Add-Member -NotePropertyName name -NotePropertyValue $runningclusters.name
$o | Add-Member -NotePropertyName status -NotePropertyValue $runningclusters.status.state
$o | Add-Member -NotePropertyName PendingShutdown -NotePropertyValue $true
但我对$o 和id 和name 列的输出只是对象本身,而不是ID 行。如何使对象看起来像上面我想要的对象?
【问题讨论】:
标签: powershell amazon-web-services tagging psobject