Powershell Parse XML and create multiple files

For instnace .....................

<Item>
   <value>a</value>
   <value>b</value>
</Item>

How do I extract contents of  <value> </value>  .InnerXml or "a" to a file and create a naming convention. then do the same for  <value> </value>  .InnerXml or "b"   and so on is this possible?

[xml]$xml = (get-content "path.xml")


Foreach ($value in $Item) {

write-host $value.InnerXml

$xml.save("C:\Scripts\new.xml*")
}
This doesent work.
benpal2476Asked:
Who is Participating?
 
Dale HarrisProfessional Services EngineerCommented:
Try this:

$XML | gm

This will give you the possible properties and methods you can use.

You're looking for the last property, which is often the name of the first branch of the tree (in an Infopath Form, it's Myfields)

$XML.myfields | gm

This will give you the possible branches below this.

$XML.myfields.name

This will show you the value of the name property.  You can easily assign this to a variable.

This may or may not be completely what you need, but I think it will definitely get you started.

-Dale Harris
0
 
benpal2476Author Commented:
[xml]$xml = (get-content "path.xml")


Foreach ($value in $Item) {

write-host $value.InnerXml

#$xml.save("C:\Scripts\new.xml*")
#without the "*" it writes to ("C:\Scripts\new.xml")

}

#but I want it to get InnerText for the <value> </value> there are multiple <value> within the xml I would like to get each <value> and output that data to a seperate file.
0
 
Dale HarrisProfessional Services EngineerCommented:
Try this instead:

foreach ($group in $xmlData.benchmark.group)
{
  $group.id
  $group.title
  $group.rule.id
}


Again, you're going to want to try to get a single value at the least to make sure it's working like you planned.

DH
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
Dale HarrisProfessional Services EngineerCommented:
Also, if you'd like to have me help a little more, you can post a portion of your XML code (so I can actually run it through and attempt to work with it myself) and I'll see if I can't cook something up.

DH
0
 
benpal2476Author Commented:
[xml]$xml = (get-content "C:\Users\user\Desktop\xml")

$xml.SelectNodes("/Item/Alias") |
Select * | Format-List

I created this it gives me a break down of Alias in the document, I know there are 40 Alias from doing a .count but now i'd like to save the innertext or inner xml of Alias to a seperate file.

Thanks for your time.
0
 
Dale HarrisProfessional Services EngineerCommented:
Using the following command will help:
$VariablewithStuffInside| get-member

This is the best way to see what kind of properties and method are in that object, just so you can see if you can hit a command to make it work.

I would love your xml file  you're actually importing with 40 aliases.  This way, I can just take a few minutes to look it over, generate the exact code you need, since you seem to having a difficulty getting the information you need out of this.

DH
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.