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
Reading XML Files
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.
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.
Reading XML Files
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")
Reading XML Files
Another method that shows how to get at teh embedded pieces in order.
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
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
Reading XML Files
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
Reading XML Files
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