Author Posts

January 1, 2012 at 12:00 am

by slash85 at 2012-09-24 01:50:44

Hi all,

I'm trying to store the XML attribute values from this command:

[xml]$userfile = get-content test.xml

$NAME = $userfile | select-xml -xpath "//NAME//@SNAME"


However this does not output the value only the node information (as below)

Node Path Pattern
—- —- ——-
SNAME InputStream //NAME//@SNAME
SNAME InputStream //NAME//@SNAME
SNAME InputStream //NAME//@SNAME

How can i retrieve the actual values in SNAME and store in a variable?

Many Thanks for any help – i'm sure it's easy but i'm not having much luck.

I've tried piping to | foreach {$_.value} but still nothing?


by DonJ at 2012-09-24 06:34:39

I'm not the awesome-est at XML manipulation, but in general you'll want to pipe whatever you've got to Get-Member. That'll show you what it's made of. Could you post a short excerpt of your XML? Not the whole thing, just a short version. It's hard to help you with this without knowing what the input looks like.

by surveyor at 2012-09-24 07:28:54

Hi slash,
with a little modification from this thread it shows maybe what you need:

$myxml = [xml]@"
< ?xml version="1.0" encoding="utf-8" standalone="no" ?>



# get attributes
$Field2 = Select-Xml -Xml $myxml -XPath "/fieldData/map/field[@name='Field 2']"

# get the value
$Field3 = Select-Xml -Xml $myxml -XPath "/fieldData/map/field[@name='Field 3']"
# or better