Search notes:

PowerShell: Iterate over array that contains name/value pairs

In PowerShell, when an array is assigned to an array with fewer elements ($e1, $e2, $rest = $a, $b, $c, $d…), the values of $e… are assigned from the left ($e1 = $a, $e2 = $b etc.) and the last element $rest is assigned the remaining values as an array. This feature can be used to iterate over an array that contains name/value pairs, as showh in the following simple example script:
$name_value_pairs = 'text', 'hello World', 'number', 42, 'fruit', 'apple'

while ($name_value_pairs) {
   $name, $value, $name_value_pairs = $name_value_pairs
   write-host('{0,-7}: {1}' -f $name, $value)
}
Github repository about-PowerShell, path: /language/type/array/iterate-over-name-value-pairs.ps1
When executed, this script prints
text   : hello World
number : 42
fruit  : apple

Index