1

In Powershell, I have a list of different subroutes and I need to define all possible start/end points from the route. Let me clearify by showing an example.

This is the list of subroutes. These are all objects with a property that defines whether it is a possible starting point or not. In this example, only $A is a starting point.

$subroutes = @(
    @($A, $B),
    @($A, $C),
    @($B, $D),
    @($B, $E),
    @($D, $F),
    @($C, $E)
)

For example: you can go from A to B and then from B to 3 other destinations. The final result would be: - A ==> F (A to B to D to F) - A ==> E (A to B to E) OR (A to C to E)

I am quite new to Powershell and have learned a lot already, but I cannot seem to find a decent piece of code to manage this. What is the best combination of cmdlets to traverse all possible subroutes and make sure I can find all possible routes?

LuLuGaGa
  • 13,089
  • 6
  • 49
  • 57
plenders
  • 11
  • 1
  • 4
    There are unlikely to be any cmdlets dedicated to this as it seems quite niche for your typical Admin. It looks like a graph/path problem, for which there are [well-known algorithms](https://www.geeksforgeeks.org/find-paths-given-source-destination/). – boxdog Oct 14 '19 at 11:22
  • Can you give a used case for this? Is there any specific programming language your referring to that can do this? B.t.w. all your items are variables in your example (starting with a dollar) what do they contain? Or do you actually what this as an example: `$subroutes=@(@('A','B'),@('A','C'),@('B','D'),@('B','E'),@('D','F'),@('C','E'))`. Besides PowerShell usually flattens arrays which you might want to understand first, see e.g.: [Why does PowerShell flatten arrays automatically?](https://stackoverflow.com/questions/57023626/why-does-powershell-flatten-arrays-automatically) – iRon Oct 14 '19 at 11:52

0 Answers0