select-xml

for openers, how do I post sample xml to this forum? the “pre” stuff isn’t working for me.

easiest way is to use gist

so here is some xml. it’s an RDG file from microsoft’s Remote Desktop Connection Manager.

https://gist.github.com/Curtmcgirt/15834c2838a07023868f7cc8b6cc3e7c

assume $xml = [xml](get-content testrdg.rdg)

$xml.rdcman.file.group.server.name returns “testserver”.

$xml.selectnode("//rdcman/file/group/server/name") returns nothing
$xml | select-xml -XPath “//rdcman/file/server/properties/name” returns nothing

I’ve read that this has to do with “namespace,” and I have to define a namespace. but I don’t see a namespace defined in that xml, so I don’t know how to decide what namespace to tell powershell to use.

crickets?

XPath is case-sensitive.

Using your example XML, these work.

Select-Xml -Xml $xml -XPath "//RDCMan/file/group/server/properties/name"
$xml.SelectNodes("//RDCMan/file/group/server/properties/name")