I have the following code in PowerShell:
[xml]$Xml = @"
<?xml version="1.0" encoding="utf-8"?>
<Sequences>
<Sequence>
<SequenceName>Sequence-A</SequenceName>
<SequenceMeta>
<SequenceStart>2019-07-23T17:26:54.710+02:00</SequenceStart>
<SequenceEnd>2019-07-23T17:26:54.741+02:00</SequenceEnd>
</SequenceMeta>
</Sequence>
<Sequence>
<SequenceName>Sequence-B</SequenceName>
<SequenceMeta>
<SequenceStart></SequenceStart>
<SequenceEnd></SequenceEnd>
</SequenceMeta>
</Sequence>
</Sequences>
"@
Clear-Host
$Sequences = $Xml.Sequences.Sequence | Where-Object -Property SequenceMeta.SequenceEnd
$Sequences
Remove-Variable -Name Xml
As you see I load XML-Data and then I want to filter it with "Where-Object". I want to select those "Sequence(s)", where the property "SequenceEnd" has a value.
In this example, the result should be "Sequence-A". "Sequence-B" should not be shown in the results, because the "SequenceEnd"-property has no value.
I don't know how to select the sub-property "Sequence-End". I tried it like "SequenceMeta.SequenceEnd", but as you see this is not working.
I am looking for a one-liner. In reality the query will be much longer.
Thank you