I want to perform a check of a variable's existence while creating a PSCustomObject. I have quite a few objects to query and gather data for into my new object so I don't want to duplicate the entire code block with an "if" statement as I'm trying to be concise.
[array]$newObject += [PSCustomObject][ordered]@{
JitterInterArrival = (if ($_.QoeReport.AudioStreams){$_.QoeReport.AudioStreams[0].JitterInterArrival}else{"N/A"}
}
I know the above block produces an error that the "if" statement isn't recognized. Is there another way to include a code block while defining the PSCustomObject?