I have this XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Clients xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<set>
<name>mario1</name>
<sn>GSI100-A-00100</sn>
<status>OK</status>
<version>V</version>
</set>
<set>
<name>mario2</name>
<sn>GSI100-A-00101</sn>
<status>OFF</status>
<version>v49</version>
</set>
<set>
<name>mario3</name>
<sn>GSI100-A-00101</sn>
<status>OK</status>
<version>v49</version>
</set>
</Clients>
and am trying to locate a node with <name>
equal to the value of a variable (in this case $find
) and trying to return the innertext of the <status>
element of the same node. This is what I do, but all I get is null.
$xmledit = New-Object System.Xml.XmlDocument
$xmledit = "C:\Users\bigadmin\Desktop\Projects\AutoUpdate\test.xml"
[xml]$Xmlnew = Get-Content ($xmledit) -Encoding UTF8
$find = "mario1"
foreach ($search in $Xmlnew.clients.set) {
$nodeexists = $search.SelectSingleNode("name") |
Where {$_.nodeexists -eq "$find"}
return $nodeexists.clients.set.sn.InnerText
}