I have a simple XML
10
john
pc24
You can use a slightly smarter XPath to select your nodes, and then the InnerXml
property to get the output string you're after:
PS> $xml = [xml] @"
10
john
pc24
12
peter
pc25
"@
PS> $xml.SelectNodes("bds/bd[servers/name = 'pc25']").InnerXml
12 peter pc25
Note - bds/bd[servers/name = 'pc25']
means "find all the bds/bd
nodes that have a child servers/name
node with a value pc25
".
You can then retro-fit this back into your function using your variable values in the XPath string as appropriate...