XML PowerShell - Fetch all the XML Nodes with based on an Attribute Value

I am trying to fetch all the XML nodes, where Attribute “Tag” value is “Fetch” with a XPath, without looping much using PowerShell 5.1. Please help.

[xml] $XMLValue=@'
<Root>
<Child>
    <Parameter Tag="Fetch"><![CDATA["Data"]]></Parameter>
    <Parameter Tag="DontFetch"><![CDATA["Data"]]></Parameter>
</Child>
<Child>
   <Test>
      <Node Tag="Fetch"><![CDATA["Data"]]></Parameter>
      <Node Tag="DontFetch"><![CDATA["Data"]]></Parameter>
   </Test>
</Child>
<Child>
    <Test>
        <Test1>
            <Node1 Tag="Fetch"><![CDATA["Data"]]></Parameter>
            <Node2 Tag="DontFetch"><![CDATA["Data"]]></Parameter>
        </Test1>
    </Test>     
</Child>
</Root>
'@

I’m sorry, but your example is completely blank. Give it another whirl, or maybe upload it as a Gist for easier reading :slight_smile:

Like this? Xpath is case sensitive.

select-xml "//*[@Tag='Fetch']" file.xml

Node      Path                       Pattern
----      ----                       -------
Parameter /Users/js/foo/file.xml //*[@Tag='Fetch']
Node      /Users/js/foo/file.xml //*[@Tag='Fetch']
Node1     /Users/js/foo/file.xml //*[@Tag='Fetch']

I didn’t think xml would post here at all. You have several errors in the xml where you mix up “Node” and “Parameter”. I edited my answer to match the case.