Freitag, 10. Februar 2012

Use XPath expressions with Power Shell

Find all unique values within XML file and write output to file.

Select-Xml -path "Sample.xml" -xpath "/descendant::Lastname/text()" | foreach-object {$_.Node.Value} | sort | get-unique | out-file "out.txt"

Use it with XML namespaces

Select-Xml -path "Sample.xml" -xpath "/descendant::ns:StyleColorStatus/text()" -Namespace @{ns="http://SampleNamespace"} | foreach-object {$_.Node.Value} | sort | get-unique | out-file "c:\temp\out.txt"