Nawad-sama
Nawad-sama

Reputation: 181

Group Objects within already grouped objects

I'm trying to prepare a list of files with duplicate names but different extensions. At the same time I'd like to exclude files with the same extension. So far I've created this

gci -path "PATH" -recurse -file -erroraction silentlycontinue|
Select @{l='Original Filename';e={$_.PSChildName}},  @{l='Compare Filename';e={$_.BaseName.replace('_','*').replace(' ','*').replace('-','*')}}, @{l="Path";e={$_.PSParentPath.Substring(38,$_.PSParentPath.Length-38)}}, @{l="Link";e={$_.FullName}}, @{l="Extension";e={$_.Extension}}
group -Property 'Compare Filename'|
Where {$_.count -ge 2}|
%{$_.group}|
Export-Csv -Path "PATH" -NoTypeInformation

I figured I'd need to group objects within already grouped objects by 'extension' property and discard those groups where 'extension groups' count is less than 2.

Exmaple

Include
Name Ext
asd  .pdf
asd  .ppt


Exclude
asd  .pdf
asd  .pdf

Any ideas?

Upvotes: 0

Views: 53

Answers (0)

Related Questions