theB3RV
theB3RV

Reputation: 924

Powershell select where attribute exists

I have three nodes with the same name but with different attributes. I would like to only select the one where the bar attribute exists.

<Test foo="Hello" />
<Test bar="World" />
<Test zed="Goodbye" />

Upvotes: 0

Views: 158

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174435

You could use XPath for this:

Select-Xml -Path path\to\file.xml -XPath '//Test[@bar]'

//Test will resolve any <Test> nodes anywhere in the tree, [@bar] filters them by whether they have a bar attribute or not

Upvotes: 2

Related Questions