becraig
asked on
Powershell Select from xml
I need to be able to select from an xml based on a value then parse for specific child nodes in that parent and perform specific functions:
Here is the xml snippet:
Now I do not have any control over the xml formatting so unless someone is willing to do the heavy lifting to change the xml that is all I have to work with.
I want to be able to do something similar to below:
Select * from xml where server = "server01"
Then I want to query for all the virtuals for that machine then do a foreach loop:
e.g
foreach ($virtual in$virtuals)
{ do something}
Let me know if anyone thinks they can help :)
Here is the xml snippet:
<ServerList>
<Server Name="SERVER01">
<IP Address="192.16.1.1" Status="In Service" Virtual="8.8.8.55" />
<IP Address="192.16.1.2" Status="In Service" Virtual="8.8.8.66" />
<IP Address="192.16.1.3" Status="In Service" Virtual="8.8.8.77" />
</Server>
<Server Name="SERVER02">
<IP Address="192.16.1.19" Status="In Service" Virtual="8.8.8.55" />
<IP Address="192.16.1.14" Status="In Service" Virtual="8.8.8.66" />
<IP Address="192.16.1.17" Status="In Service" Virtual="8.8.8.77" />
</Server>
<Server Name="SERVER03">
<IP Address="192.16.1.44" Status="In Service" Virtual="8.8.8.55" />
<IP Address="192.16.1.48" Status="In Service" Virtual="8.8.8.66" />
<IP Address="192.16.1.56" Status="In Service" Virtual="8.8.8.77" />
</Server>
<Server Name="SERVER04">
<IP Address="192.16.1.78" Status="In Service" Virtual="8.8.8.55" />
<IP Address="192.16.1.68" Status="In Service" Virtual="8.8.8.66" />
<IP Address="192.16.1.97" Status="In Service" Virtual="8.8.8.77" />
</Server>
</ServerList>
Now I do not have any control over the xml formatting so unless someone is willing to do the heavy lifting to change the xml that is all I have to work with.
I want to be able to do something similar to below:
Select * from xml where server = "server01"
Then I want to query for all the virtuals for that machine then do a foreach loop:
e.g
foreach ($virtual in$virtuals)
{ do something}
Let me know if anyone thinks they can help :)
Good news :)
Would you consider posting the solution so other people can benefit from it?
D
Would you consider posting the solution so other people can benefit from it?
D
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The key was in using _.Node.ParentNode to specify the parent node of the node I was specifying in my query.
ASKER