Convert a list of key value pairs to a hashtable

powershell

Solution

Try the following

$table = new-object System.Collections.Hashtable
for ( $i = 0; $i -lt $list.Length; $i += 2 ) {
  $table.Add($list[$i],$list[$i+1]);
}

Problem

What is the best way to convert a List to a Hashtable? Say I have a list like `("Key",$value,"Key2",$value2)` What is the shortest syntax to convert it into a Hashtable?

Original source