I'm guessing this is pretty simple, I'm just starting with powershell and I can't seem to find a simple solution after a few hours searching the net.
Basically I have the following xml file
<Config>
<System>
<Server>
<Name>host1</Name>
<Service>service1</Service>
<Service>service2</Service>
</Server>
<Server>
<Name>host2</Name>
<Service>service1</Service>
</Server>
</System>
<System2>
<Server>
<Name>host1</Name>
<Service>service1</Service>
<Service>service2</Service>
</Server>
<Server>
<Name>host2</Name>
<Service>service1</Service>
<Service>service2</Service>
<Service>service3</Service>
</Server>
</System2>
</Config>
And I would like to get the contents into a jagged 2d array, so system would wind up as follows:
- (host1),(service1,service2)
- (host2),(service1)
Is it possible to iterate through each element and create such an array?
I'm hoping to store the data as above so that I can use [0][0] to reference the hostname and then [1][1..x] to reference all services for that host.
Does that make any sense?
Any help or better appraoch is greatly appreciated.
You might think about using a hashtable for this instead. You can still iterate over the results and you can look up results by hostname e.g.:
Outputs: