There are many ways to do this, depending on what you need. In this article Iโm going to highlight 2 of them.
Function-style conversion:
1 2 3 4 5 6function ArrayToHash($a) { $hash = @{} $a | foreach { $hash[$_.ProcessName] = $_ } return $hash }Usage:
1ArrayToHash (Get-Process)Filter-style conversion:
1 2 3 4 5 6filter ArrayToHash { begin { $hash = @{} } process { $hash[$_.ProcessName] = $_ } end { return $hash } }Usage:
1Get-Process | ArrayToHash