I needed a simple PowerShell code to generate hash tables with all possible pairs of a given array of strings. There are possibilities to use a similar method in .NET but I used only PowerShell functionality. This is my output:
$inputItems = 'aaa', 'bbb', 'ccc' $pairItems = @() $i = 0 foreach ($pairItemFirst in $inputItems) { foreach ($pairItemSecond in ($inputItems | Where-Object -FilterScript { $_ -ne $pairItemFirst })) { $pairItems += [ordered]@{ PairNumber = $i First = $pairItemFirst Second = $pairItemSecond } } $i++ } $pairItems
Output:
Name Value ---- ----- PairNumber 0 First aaa Second bbb PairNumber 0 First aaa Second ccc PairNumber 1 First bbb Second aaa PairNumber 1 First bbb Second ccc PairNumber 2 First ccc Second aaa PairNumber 2 First ccc Second bbb