Suppose I have the following XML file, and I want to use PowerShell (version 1.0) to manipulate the XML file to get the value for Foo (in this sample, value I want to get is “Foo Value”) and Goo (in this sample, value I want to get is “Goo Value”), any ideas how to implement?
$FooConfig = [xml](get-content .\Foo.exe.config -ErrorAction:stop)
<configuration>
<appSettings>
<add key="Foo" value="Foo Value" />
<add key="Goo" value="Goo Value" />
</appSettings>
</configuration>
thanks in advance,
George
The XPath API is very alive under PowerShell (your XML is, after all, just .NET objects), and it can often be the easiest to use if you just want a value:
Or if you want to enumerate the add elements as a PowerShell collection (a bit more PowerShell’ish 🙂
Will print
And of course, you can pipe that result to additional commands to do whatever processing you like.