How to get the parent node of a given child node using PowerShell?
Posted
by
kumar
on Super User
See other posts from Super User
or by kumar
Published on 2012-10-24T07:48:55Z
Indexed on
2012/10/24
11:04 UTC
Read the original article
Hit count: 333
powershell
|Xml
I am new to PowerShell. I have to write a script which can return me the first parent(node) value by passing the child node.
I have the following XML. When I pass my PowerShell script the value "AAA", it should return "parent2", and when I pass "III", it should return "parent311".
Can someone help me write this script?
XML:
<root>
<parent>
<parent2>
<child>AAA</child>
</parent2>
<parent3>
<child>BBB</child>
<child>CCC</child>
<child>DDD</child>
</parent3>
<parent4>
<child>EEE</child>
</parent4>
<parent5>
<child>FFF</child>
</parent5>
</parent>
<parent21>
<parent211>
<child>GGG</child>
</parent211>
<parent311>
<child>HHH</child>
<child>III</child>
<child>JJJ</child>
</parent311>
<parent411>
<child>KKK</child>
</parent411>
<parent511>
<child>LLL</child>
</parent511>
</parent21>
</root>
© Super User or respective owner