Reading XML Files

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 15 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
boyddt_co
Posts: 89
Last visit: Mon Sep 25, 2023 9:36 pm

Reading XML Files

Post by boyddt_co »

I have the xml files from backup exec, from which I'd like to pull some of the information from. The layout is as such<joblog> <backup> <machine> <machine_name> <set> <set_resource_name> </set_resource_name> <summary> </summary> </set> <set>
<set_resource_name>
</set_resource_name>
<summary>
</summary> </set> <set>
<set_resource_name>
</set_resource_name>
<summary>
</summary>
</set> </machine_name> </machine> </backup></joblog>in
each file there are multiple machine items and I would like to pull out
the machine name, resource name and summary for each machine. I'm new
to powershell but have been scripting with vbscript for some time. I've
looked through some examples but they don't go through multi-level
multi-selection options. If someone could give me a hand I would really
appreciate it.Thanx in advance,David
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Reading XML Files

Post by jvierra »

For your file:

Code: Select all

	
[xml]$xml=gc BEX_US07-BACKUP1_07570.xml
	
$xml.SelectNodes("//machine_name")
	
$xml.SelectNodes("//resource_name")
	
$xml.SelectNodes("//summary")
	
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Reading XML Files

Post by jvierra »

Another method that shows how to get at teh embedded pieces in order.

Code: Select all

	
$machines=$xml.selectNodes("//machine")
foreach($m in $machines){"NAME:"+$m.machine_name;foreach($set in $m.set){"RESOURCE:"+$set.set_resource_name;"SUMMARY:";$set.summary.misc}}
	

I would like to note that this is much easier to do using XSLT as it can perform all of the conversions and formatting more easily. If you are just looking for a report then consider XSLT as it is much more direct and does not require the alteration of files or the installation of PowerShell. If you need to integrate the Backup data with other information using PowerShell then the above should get you started.

Backup Exec XML is a nightmare as it is schema-less and is what I call, broken xml. It doesn't follow a consisitent set of rules and has a slightly schizoid hierarchy. This is probably due to it's legacy nature . It was also never intended for public consumption.


jvierra2008-05-22 11:59:42
User avatar
boyddt_co
Posts: 89
Last visit: Mon Sep 25, 2023 9:36 pm

Reading XML Files

Post by boyddt_co »

jvierra, that is exactly what I needed. Now I need to just sit down and figure out why it works.Thanx again for the help.David
User avatar
boyddt_co
Posts: 89
Last visit: Mon Sep 25, 2023 9:36 pm

Reading XML Files

Post by boyddt_co »

Network Geek, though I tried to parse the Backup Exec files through Powershell, it is a new environment for me and I struggled more than I should have. I ended up using vbScript and have it running. If you would like, contact me at david . boyd at synthes . com and I can forward you the code that I have.David
User avatar
boyddt_co
Posts: 89
Last visit: Mon Sep 25, 2023 9:36 pm

Reading XML Files

Post by boyddt_co »

in your command file you reference logparser, what is that?
This topic is 15 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked