我刚刚开始搞乱PowerShell和JSON。我知道如何在.vbs中执行此操作,但我似乎无法弄清楚如何从我在PSCustomObject中放入的JSON流中访问信息。
这是我能得到的全部内容:
PS C:\Windows\system32> $new = ConvertFrom-Json $res
PS C:\Windows\system32> $new
5ab3cf621ff74b7d84b6604d268dc2e3
--------------------------------
@{timezone=-18000; org=DWSC; name=dx-dc01; summary=System.Object[]}
这是整个流:
{
"5ab3cf621ff74b7d84b6604d268dc2e3": {
"timezone": -18000,
"org": "DWSC",
"name": "dx-dc01",
"summary": [
{
"jobs_aborted": 0,
"img_total": 97,
"total_size": 3471175680,
"ts": "2014-12-22",
"jobs_successful": 97,
"jobs_failed": 0
},
{
"jobs_aborted": 0,
"img_total": 98,
"total_size": 4135197184,
"ts": "2014-12-21",
"jobs_successful": 98,
"jobs_failed": 0
},
{
"jobs_aborted": 0,
"img_total": 98,
"total_size": 2142773760,
"ts": "2014-12-20",
"jobs_successful": 98,
"jobs_failed": 0
},
{
"jobs_aborted": 0,
"img_total": 98,
"total_size": 3241462784,
"ts": "2014-12-19",
"jobs_successful": 98,
"jobs_failed": 0
},
{
"jobs_aborted": 0,
"img_total": 98,
"total_size": 3160975872,
"ts": "2014-12-18",
"jobs_successful": 98,
"jobs_failed": 0
},
{
"jobs_aborted": 0,
"img_total": 98,
"total_size": 3325648384,
"ts": "2014-12-17",
"jobs_successful": 98,
"jobs_failed": 0
},
{
"jobs_aborted": 0,
"img_total": 98,
"total_size": 3213957120,
"ts": "2014-12-16",
"jobs_successful": 98,
"jobs_failed": 0
},
{
"jobs_aborted": 0,
"img_total": 98,
"total_size": 3287087104,
"ts": "2014-12-15",
"jobs_successful": 98,
"jobs_failed": 0
},
{
"jobs_aborted": 0,
"img_total": 98,
"total_size": 4102248960,
"ts": "2014-12-14",
"jobs_successful": 98,
"jobs_failed": 0
},
{
"jobs_aborted": 0,
"img_total": 98,
"total_size": 2167602176,
"ts": "2014-12-13",
"jobs_successful": 98,
"jobs_failed": 0
},
{
"jobs_aborted": 0,
"img_total": 98,
"total_size": 2823620096,
"ts": "2014-12-12",
"jobs_successful": 98,
"jobs_failed": 0
},
{
"jobs_aborted": 0,
"img_total": 98,
"total_size": 2777434624,
"ts": "2014-12-11",
"jobs_successful": 98,
"jobs_failed": 0
},
{
"jobs_aborted": 0,
"img_total": 98,
"total_size": 3017865728,
"ts": "2014-12-10",
"jobs_successful": 98,
"jobs_failed": 0
},
{
"jobs_aborted": 0,
"img_total": 98,
"total_size": 3269979136,
"ts": "2014-12-09",
"jobs_successful": 98,
"jobs_failed": 0
},
{
"jobs_aborted": 0,
"img_total": 98,
"total_size": 3255396352,
"ts": "2014-12-08",
"jobs_successful": 98,
"jobs_failed": 0
},
{
"jobs_aborted": 0,
"img_total": 98,
"total_size": 4094169088,
"ts": "2014-12-07",
"jobs_successful": 98,
"jobs_failed": 0
},
{
"jobs_aborted": 0,
"img_total": 98,
"total_size": 2159005184,
"ts": "2014-12-06",
"jobs_successful": 98,
"jobs_failed": 0
},
{
"jobs_aborted": 0,
"img_total": 98,
"total_size": 3248604672,
"ts": "2014-12-05",
"jobs_successful": 98,
"jobs_failed": 0
},
{
"jobs_aborted": 0,
"img_total": 98,
"total_size": 3266557952,
"ts": "2014-12-04",
"jobs_successful": 98,
"jobs_failed": 0
},
{
"jobs_aborted": 0,
"img_total": 98,
"total_size": 3047322112,
"ts": "2014-12-03",
"jobs_successful": 98,
"jobs_failed": 0
},
{
"jobs_aborted": 0,
"img_total": 98,
"total_size": 3090918912,
"ts": "2014-12-02",
"jobs_successful": 98,
"jobs_failed": 0
},
{
"jobs_aborted": 0,
"img_total": 98,
"total_size": 3270432768,
"ts": "2014-12-01",
"jobs_successful": 98,
"jobs_failed": 0
},
{
"jobs_aborted": 0,
"img_total": 98,
"total_size": 3972825600,
"ts": "2014-11-30",
"jobs_successful": 98,
"jobs_failed": 0
},
{
"jobs_aborted": 0,
"img_total": 98,
"total_size": 2160855552,
"ts": "2014-11-29",
"jobs_successful": 98,
"jobs_failed": 0
},
{
"jobs_aborted": 0,
"img_total": 98,
"total_size": 2304687616,
"ts": "2014-11-28",
"jobs_successful": 98,
"jobs_failed": 0
},
{
"jobs_aborted": 0,
"img_total": 98,
"total_size": 2506697216,
"ts": "2014-11-27",
"jobs_successful": 98,
"jobs_failed": 0
},
{
"jobs_aborted": 0,
"img_total": 98,
"total_size": 3516776960,
"ts": "2014-11-26",
"jobs_successful": 98,
"jobs_failed": 0
}
]
}
}
我想我真的需要了解System.Object[]
由于
答案 0 :(得分:1)
PS C:\> $o = ConvertFrom-Json $json
PS C:\> $o.'5ab3cf621ff74b7d84b6604d268dc2e3'.summary | ft -a
jobs_aborted img_total total_size ts jobs_successful jobs_failed
------------ --------- ---------- -- --------------- -----------
0 97 3471175680 2014-12-22 97 0
0 98 4135197184 2014-12-21 98 0
0 98 2142773760 2014-12-20 98 0
0 98 3241462784 2014-12-19 98 0
0 98 3160975872 2014-12-18 98 0
0 98 3325648384 2014-12-17 98 0
0 98 3213957120 2014-12-16 98 0
0 98 3287087104 2014-12-15 98 0
0 98 4102248960 2014-12-14 98 0
0 98 2167602176 2014-12-13 98 0
0 98 2823620096 2014-12-12 98 0
0 98 2777434624 2014-12-11 98 0
0 98 3017865728 2014-12-10 98 0
0 98 3269979136 2014-12-09 98 0
0 98 3255396352 2014-12-08 98 0
0 98 4094169088 2014-12-07 98 0
0 98 2159005184 2014-12-06 98 0
0 98 3248604672 2014-12-05 98 0
0 98 3266557952 2014-12-04 98 0
0 98 3047322112 2014-12-03 98 0
0 98 3090918912 2014-12-02 98 0
0 98 3270432768 2014-12-01 98 0
0 98 3972825600 2014-11-30 98 0
0 98 2160855552 2014-11-29 98 0
0 98 2304687616 2014-11-28 98 0
0 98 2506697216 2014-11-27 98 0
0 98 3516776960 2014-11-26 98 0
PowerShell似乎不会将5ab3cf621ff74b7d84b6604d268dc2e3
识别为属性名称,即使按Tab键时它已展开。然后在它周围加上引号。