Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
构建PSCustomObject时的PowerShell条件语句_Powershell_Pscustomobject - Fatal编程技术网

构建PSCustomObject时的PowerShell条件语句

构建PSCustomObject时的PowerShell条件语句,powershell,pscustomobject,Powershell,Pscustomobject,我想在创建PSCustomObject时检查变量的存在性。我有很多对象要查询并收集数据到我的新对象中,所以我不想用“if”语句复制整个代码块,因为我尽量简洁 [array]$newObject += [PSCustomObject][ordered]@{ JitterInterArrival = (if ($_.QoeReport.AudioStreams){$_.QoeReport.AudioStreams[0].JitterInterArrival}else{"N/A"} } 我知道上

我想在创建PSCustomObject时检查变量的存在性。我有很多对象要查询并收集数据到我的新对象中,所以我不想用“if”语句复制整个代码块,因为我尽量简洁

[array]$newObject += [PSCustomObject][ordered]@{
  JitterInterArrival = (if ($_.QoeReport.AudioStreams){$_.QoeReport.AudioStreams[0].JitterInterArrival}else{"N/A"}
}
我知道上面的块会产生一个错误,即“if”语句无法识别。在定义PSCustomObject时,是否有其他方法包含代码块?

您已经非常接近了

[array]$newObject += [PSCustomObject][ordered]@{
  JitterInterArrival = $(if ($_.QoeReport.AudioStreams){$_.QoeReport.AudioStreams[0].JitterInterArrival}else{"N/A"})
}
通过用
$()
包围它,我们使它成为一个首先执行的子表达式