For each aggregate on one HashtBable, an array of HashTable [] is returned

I would like to scan the directory src/for all .pdbfiles, but deduplicate them by their names (since the same file can appear several times in different subdirectories). I thought something like that would do.

$x = ls .\src\ -Recurse -Include *.pdb | 
     % { $a[$_.Name] = $_; $a } -Begin { $a = @{} }

And it's kind of like, but surprisingly $x.GetType()there is Object[]not Hashtable. Instead, each of the elements in the array Object[]is represented Hashtable.

I really don’t understand why this is happening, it seems that there $xshould beHashtable

+4
source share
2 answers

, $a . ForEach-Object 3 : -Begin, -Process -End. -Begin -End , -Process .

, , $a -Process -End. , - -Begin, -Process, - - -End.

$x = ls .\src\ -Recurse -Include *.pdb | 
     % -Begin { $a = @{} } -Process { $a[$_.Name] = $_ } -End { $a }
+4

, . , . $a.

$a.GetType(), - enter image description here

, $x.getType() System.Objects

enter image description here

Object Array $x , Hashtable ( $a).

, .

0

Source: https://habr.com/ru/post/1677408/


All Articles