In PowerShell xml nodes can be accessed through the dot operator, like object properties. Sometimes there can be more than one node with the same name, there you can use array notation.
For example, you can get all the 'add' nodes, filter the one whose 'key' attribute's value -eq 'TCPport' and set its 'value' attribute's value to '3000' this way also:
$xml.configuration.appSettings.add |
? {$_.key -eq 'TCPport'} | % {$_.value = '3000'}
# get-member can help you discover the elements
$xml | gm -t property
# the ChildNodes property lists the node's childNodes, if any
$xml.childNodes | select name
$xml.configuration.childNodes | select name
# ...etc.
I don't know if there is a .NET property/method that will display the element list, hope I'm wrong.
Something like this gets you a list of the element names:
[xml]$xml = gc c:\data.xml
$xml | fc | out-string -str | ? {$_ -match $rgx} |
% {$h = @{}; $c = 0} {$h."$($rgx.replace($_,'$1'))" = $c++}
$elements = $h.getEnumerator() | sort {[int]$_.value} |
? {$_.name -match '^\w'} | % {$_.name}
$elements
--
Kiron