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.

  1. folders contain .msi files, don't include executable files.

  2. folders contain .exe files, don't include .msi files.

  3. 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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -