Reputation: 3927
To look for element by xpath i do:
Select-Xml -XPath "//node[a='1']" -Xml $xml
Is there a simple way (without loop) to look for all files under this directory that has element with this xpath?
Something similar to text search:
Get-ChildItem -Recurse -Include *.* | Select-String "text to search for"
version - Powershell3
Upvotes: 3
Views: 2305
Reputation: 201952
You can pipe the files you want to do an XPath search directly into Select-Xml
like so:
Get-ChildItem . -r -file | Select-Xml -XPath "//node[a='1']"
For more information on how the output of Get-ChildItem gets "connected" to the LiteralPath parameter of Select-Xml, see this blog post. You can get the whole Effective PowerShell free ebook from here.
Upvotes: 4