我确定这是一个非常基本的PowerShell问题,但是我有一个JSON文件,我将使用该文件加载到PowerShell自定义对象中,ConvertFrom-Json
以下select-object
工作
$JsonContent.value | Select-Object -Property Name, @{Name = 'commit'; Expression = { $_.commit.author.date }}
我正在尝试在嵌套的提交对象中获取另一列,而以下操作无效,因此希望有人可以帮助我弄清楚如何从嵌套的提交对象中获取第二个值(我已经尝试了一些变体但不起作用)
JsonContent.value | Select-Object -Property Name, @{Name = 'commit'; Expression = { $_.commit.author.date}, {$_.commit.commitId}}
谢谢
史考特
接下来的部分Expression = ...
是一个包含代码的脚本块,因此,如果您想返回一个值数组作为该属性的值,commit
则只需修改
Expression = { $_.commit.author.date}, {$_.commit.commitId}
至
Expression = { $_.commit.author.date, $_.commit.commitId}
这样您就可以使用commma运算符来创建并返回2元素数组
可能您宁愿制作一些代表提交的漂亮字符串,例如
Expression = { "{0} - {1}" -f $_.commit.author.date, $_.commit.commitId }
如果您希望commitId
在完全不同的列中添加另一个属性,如下所示
... -Property Name, @{Name = 'commit'; Expression = { $_.commit.author.date}}, @{Name = 'commitId'; Expression = {$_.commit.commitId}}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句