简体   繁体   中英

Group-Object in powershell, select first item in each group

Given the following script.

$module = # get path
$code = get-childitem $module -recurse -include *.dll
$list = $code | group-object -Property Name
$list

I retreive the following:

Count Name                      Group                                                                                                                                                         
----- ----                      -----                                                                                                                                                         
    4 FileA...                  {A, B, C, D}
    2 FileB...                  {X, Z}
    1 FileX...                  {R}

How do I select the first item in each group.
I want to group by the file name, but actually retrieve the first file (full path) in each group.

I want to obtain A,X,R etc

如果我理解正确,应该这样做:

$list | %{$_.Group[0].FullName}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM