Recurse with PowerShell's Get-ChildItem -
this seems should simple, , i'm sure is, i've not cracked best way should done.
i want search through folder structure returning folders meet following conditions.
folders contain .msi files, don't include executable files.
folders contain .exe files, don't include .msi files.
folders contain both exe , msi files.
each of these piped column in csv file.
my problem can't work out how return folder names include 1 file type, exclude another. know on paper seems simple using -include *.msi
, -exclude *.exe
, etc., command such gci -recurse -include *.msi -exclude *.exe
includes folders containing msi , exe folder want folder containing msi's returned.
i using following directory structure test
msi only
msi , exe
exe only
does make sense?
i experimenting | directory -notcontains *.exe
, kinds of similar things, none of them worked way wanted or expected.
unfortunately include , exclude work recurse parameter. won't able exclusion without recursion.
here's alternative.
$folders = dir -path ~ -recurse | ? {$_.psiscontainer} $folders | foreach-object { $exe_files = $_ | dir -filter *.exe $msi_files = $_ | dir -filter *.msi $type = '' if ($exe_files -and $msi_files) {$type = 'both'} if ($msi_files -and -not $exe_files) {$type = 'msi_only'} if ($exe_files -and -not $msi_files) {$type = 'exe_only'} if ($type) { new-object -typename psobject -property @{path=$_.fullname;type="$type"} } } | convertto-csv | set-content ~\out.csv
Comments
Post a Comment